Below is some coding I have calculating percent error of Euler's method however there has to be a more efficient way to input the matrices, I have found the first two step size errors by manually inputing the values but before I do the third (extremely long), there has to be a faster way. Any suggestions?
%%Analytical
simplify(dsolve('Dy=-x/y','y(0)=5','x'))
%%Numerical
f=@(x) (-x^2+25)^(1/2)
dydx=@(x,y) -(x/y);
[x1,y1]=eulode(dydx, [0 5],5,.5);
[x2,y2]=eulode(dydx,[0 5],5,.1);
[x3,y3]=eulode(dydx,[0 5],5,.01);
disp([x1,y1])
disp([x2,y2])
disp([x3,y3])
%%Percent Error
x1=0:.5:5;
x2=0:.1:5;
x3=0:.01:5;
analytical_step1= (-x1.^2+25).^(1/2)
analytical_step2=(-x2.^2+25).^(1/2);
analytical_step3=(-x3.^2+25).^(1/2);
numerical_1=[5.000 5.000 4.9500 4.8490 4.6943 4.4813 4.2024 3.8454 3.3903 2.8004 1.9970 ]
numerical_2=[5.0000 5.0000 4.9980 4.9940 4.9880 4.9800 4.9699 4.9579 4.9437 4.9276 4.9093 4.8889 4.8664 4.8418 4.8149 4.7858 4.7545 4.7208 4.6848 4.6464 4.6055 4.5621 4.5161 4.4673 4.4159 4.3615 4.3042 4.2438 4.1802 4.1132 4.0427 3.9685 3.8904 3.8081 3.7214 3.6301 3.5337 3.4318 3.3240 3.2096 3.0881 2.9586 2.8200 2.6711 2.5101 2.3348 2.1421 1.9273 1.6835 1.3984 1.0480];
Percent_Error1=abs((analytical_step1-numerical_1)/analytical_step1)*100%answer displayed in percent
Percent_Error2=abs((analytical_step2-numerical_2)/analytical_step2)*100%answer displayed in percent

 採用された回答

bym
bym 2011 年 3 月 28 日

0 投票

Just use your definition of f to obtain all values at once (do not re-use variables like y1 etc):
Percent_Error1 = abs((y1-f(x1))./f(x1));
where x1 and y1 are outputs from your function eulode()

7 件のコメント

Alagesan
Alagesan 2014 年 3 月 31 日
I just would like to know why the percent of error is used here? can I know why?
Ella
Ella 2015 年 12 月 20 日
Is the answer pf this equation already in percentage or we still need to times it by 100 ?
Image Analyst
Image Analyst 2015 年 12 月 20 日
Looks to me like it's a fraction, so to get percentage you'd have to multiply by 100.
dfsdf
dfsdf 2022 年 9 月 15 日
COMO MRD TE FUNCIONA EL COMANDO CAUSA PTMR
dfsdf
dfsdf 2022 年 9 月 15 日
AYUDAME P
dfsdf
dfsdf 2022 年 9 月 15 日
OE RES BOTAO
Walter Roberson
Walter Roberson 2022 年 9 月 15 日
Disculpas, pero Google tiene problemas para traducir "MRD" y "PTMR"

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

その他の回答 (0 件)

タグ

質問済み:

2011 年 3 月 27 日

コメント済み:

2022 年 9 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by