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

 Risposta accettata

bym
bym il 28 Mar 2011

0 voti

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 Commenti

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

Accedi per commentare.

Più risposte (0)

Tag

Richiesto:

il 27 Mar 2011

Commentato:

il 15 Set 2022

Community Treasure Hunt

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

Start Hunting!

Translated by