MATLAB: Subscript indices must either be real positive integers or logicals help line u1(0)=2 matlab euler clear close all; h = 0.5; N = 10; u1(0)= 2 ; u2(0)= 3 ; t(0) = 2; for n=0:10 u1(n+1)=u1(n) +h*u2(n); u2(n+1)=u2(n) +h*(4*exp(0.8*t(n))-(0.5)*u1(n)); t(n+1)= t(n) + h ; end plot(u1,u2); Best Answer Positive integers are integers greater than 0. This works: h = 0.5;N = 10;u1(1)= 2 ;u2(1)= 3 ;t(1) = 2;for n=1:10 u1(n+1)=u1(n) +h*u2(n); u2(n+1)=u2(n) +h*(4*exp(0.8*t(n))-(0.5)*u1(n)); t(n+1)= t(n) + h ;endplot(u1,u2); Related SolutionsMATLAB: I keep getting an error saying index exceeds matrix dimensions Initialize n at 0:n=0;t(1)=0;T(1)=50;Tout=375; k=0.0035; time=[0.0,0.5,2.0];temps=[106,96,102];h=30;while T<160 n=n+1;slope=-k*(T(n)-Tout);t(n+1)=t(n)+h;T(n+1)=T(n)+h*slope; endor increase n later in the loop:n=1;t(1)=0;T(1)=50;Tout=375; k=0.0035; time=[0.0,0.5,2.0];temps=[106,96,102];h=30;while T<160 slope=-k*(T(n)-Tout);t(n+1)=t(n)+h;T(n+1)=T(n)+h*slope;n=n+1;end MATLAB: Plot function is not working Your plotting code is trying to select just one element from the t and y vectors.I think you want this instead:plot(t,y)(I changed my answer a bit after your edit.) Related QuestionI am trying to plot, at x=pi/4, the variation of the error percentage along h (h increments from 0.01 to 0.5), using the first order central difference method for function f(x)=sinx. Can’t figure out what’s wrong with the code. Any help pleaseCounting occurrences of a pointer
Best Answer