필터 지우기
필터 지우기

Creating a for loop that uses different numbers for a variable for an ode function, and plotting those results

조회 수: 2 (최근 30일)
Hello, I'm having trouble creating a for loop that would allow a variable in the code to change as it ran, so then I would have different results after a loop was completed. I keep getting an error that the arrays arent concatanated properly. The for loop would have to have a ode 45 function I had included but I'm getting confused in the for loop syntax. Im supposed to plot the result when ever the variable is changed, so four different plots on the same graph. Any help would be great. Thank You
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 11월 3일
What is the intention of
P=zeros(4,length(100));
? length(100) is length(a scalar) which is 1, so that is zeros(4,1)
P=P(i,j);
You replace all of P with one particular location in P. After the loop, P will be a scalar because of that, and P(i) will not exist for the plot() call.
Also, you are overwriting all of ts each iteration of the for loop. In this particular case you should be able to get away with that because you passed in a tspan that is a vector of length more than 2, in which the output times should be exactly the same as you passed in for tspan.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by