My Euler Method Error

6 ビュー (過去 30 日間)
Bob
Bob 2015 年 10 月 7 日
編集済み: Bob 2015 年 10 月 13 日
Question:
Consider the initial value problem: dy/dt= e−t − 3y, y(−1) = 0.
Part a: Use the MATLAB program myeuler.m from Chapter 8 to compute the Euler Method approximation to y(t) with step size h = 0.5 and n = 4 steps. The program will generate a list of ordered pairs (ti, yi). Use plot to graph the piecewise linear function connecting the points (ti, yi). Repeat with h = 0.2 and n = 10.
Code:
f = @(t,y) exp(-t)-3*y;
[t, y] = myeuler(f,-1,0,1,4);
plot(t,y)
[t, y] = myeuler(f,-1,0,1,10)
plot(t,y)
  5 件のコメント
Bob
Bob 2015 年 10 月 13 日
I keep getting an error:
Error in Project_2 (line 94) [t, y] = myeuler(f,-1,0,1,4);
Bob
Bob 2015 年 10 月 13 日
Need help with this asap!
Thanks

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2015 年 10 月 13 日
Your code executes without error when I try it without change.
Make sure that the code you posted for myeuler is saved in myeuler.m and that the directory it is saved in is on your MATLAB path (for example if you are cd'd to the same directory)
  5 件のコメント
Bob
Bob 2015 年 10 月 13 日
編集済み: Bob 2015 年 10 月 13 日
Now I am getting this:
Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N) to change the limit. Be aware that exceeding your available stack space can crash MATLAB and/or your computer.
Bob
Bob 2015 年 10 月 13 日
編集済み: Bob 2015 年 10 月 13 日
What is which -all myeuler? Should I have that somewhere in the code?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by