I have made the following code (C1) using arrays. I undertsand this is bad practise so i tried to write it again this time vectorising the equations but i keep getting "Array indices must be positive integers or logical values."
%C1: Loop with array
n=0.1;v=[];for i=1:n:4.9 v=[v 0.1553567*((i)^6)-2.0416*((i)^5)+9.1837*((i)^4)-14.829*((i)^3)-1.3703*((i)^2)+32.821*(i)-1.3155];endfor i=4.9:n:15.3 v=[v 0.003980879*(i^5)-0.2247*(i^4)+4.8682*(i^3)-50.442*(i^2)+254.67*(i)-430.66];endfor i=15.4:n:25 v=[v -0.073*(i^2)+6.1802*(i)+40.423];enddisp(v)t=0.9:n:25;plot(t,v)%C2: Loop with vectors
n=0.1;v=[];for i=1:n:4.9 v(i)= 0.1553567*((i)^6)-2.0416*((i)^5)+9.1837*((i)^4)-14.829*((i)^3)-1.3703*((i)^2)+32.821*(i)-1.3155;endfor i=4.9:n:15.3 v(i)=0.003980879*(i^5)-0.2247*(i^4)+4.8682*(i^3)-50.442*(i^2)+254.67*(i)-430.66;endfor i=15.4:n:25 v(i)= -0.073*(i^2)+6.1802*(i)+40.423;enddisp(v)t=0.9:n:25;plot(t,v)
Best Answer