what are yi, c1 and c2. Are c1 and and c2 even defined. Also, do you mean y(i) instead of yi.
solving a function with indecis
    2 ビュー (過去 30 日間)
  
       古いコメントを表示
    
I want to compute a function f, for example, f=sin(t*x) with this recursive algorithm.
      h=.01;y0=1;t0=0;
for i=0:10
   t(i+1)=ti+h;
   c1=func(ti, yi);
   c2=func(ti+(h/2),yi+(h/2)*c1);
   y(i+1)=yi+h/6*(c1+2*c2);
end
And I defined function func in the separate file. This loop doesn't run from the first line. I don't know what is the problem. First I want to know this way of writing indices is correct? second, how can I get the value of y at the end? Could you please help me with this? Thank you
2 件のコメント
採用された回答
  Torsten
      
      
 2018 年 4 月 23 日
        All variables must be defined before you use them.
Look at the first line of your loop: here, yi, c1 and c2 are not yet defined to calculate y(2).
Best wishes
Torsten.
12 件のコメント
  Torsten
      
      
 2018 年 4 月 23 日
				with max(Y-y) I don't get the right result
Why ? What's the problem with
max(abs(Y(:,1)-y(:)))
?
その他の回答 (0 件)
参考
カテゴリ
				Help Center および File Exchange で Startup and Shutdown についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


