Matlab % Error for Euler's Method

In summary, the conversation is about finding the percent error in Euler's method using 3 different step sizes. The speaker has some code for calculating the error but is looking for a more efficient way to input the matrices. They then provide their code for the analytical and numerical solutions, as well as the calculated percent error for each step size. There is also a question about why y1 is not the transpose of numerical_1, y2 the transpose of numerical_2, etc.
  • #1
John31
5
0

Homework Statement


I am trying to find the percent error in Euler's method with 3 different step sizes.



The Attempt at a Solution



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?

Code:
%% 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
 
Physics news on Phys.org
  • #2
Unless I'm misunderstanding the code, why isn't y1 just the transpose of numerical_1, y2 the transpose of numerical_2, etc?
 

What is "Matlab % Error for Euler's Method"?

"Matlab % Error for Euler's Method" is a mathematical concept used to measure the accuracy of the numerical solution obtained from using Euler's Method in Matlab. It is expressed as a percentage and indicates the difference between the approximate solution and the exact solution.

How is the % error calculated for Euler's Method in Matlab?

The % error for Euler's Method in Matlab is calculated by first finding the absolute difference between the approximate solution and the exact solution. This difference is then divided by the exact solution and multiplied by 100 to convert it into a percentage.

What is a good % error for Euler's Method in Matlab?

A good % error for Euler's Method in Matlab depends on the specific problem being solved. Generally, a lower % error indicates a more accurate solution. However, it is important to consider the complexity of the problem and the limitations of the method when determining a good % error.

How can I improve the % error for Euler's Method in Matlab?

To improve the % error for Euler's Method in Matlab, you can decrease the step size used in the method. This will result in a more accurate approximation of the solution, but may also increase the computational time. You can also try using a different numerical method that may be more accurate for the specific problem.

Can the % error for Euler's Method in Matlab be negative?

No, the % error for Euler's Method in Matlab cannot be negative. It is always expressed as a positive value to indicate the difference between the approximate solution and the exact solution. A negative value would not make sense in this context.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
14
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
880
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
3K
  • Classical Physics
Replies
4
Views
892
  • Engineering and Comp Sci Homework Help
Replies
7
Views
886
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
123
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
827
Back
Top