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