I need to solve a cauchy problem with the Euler Method.
Show older comments
Hi all. I was asked to solve this problem by my teacher:
I have to write a function that solves this cauchy problem with the Eulerian method, using an h (step size) of 0.25, in the interval [0,2].

I am then told:
"knowing that the exact solution of the equation is y(x)=cos(x)+sin(x), calculate the error committed in estimating y(2)."
I have to also make a graph of both the true solution (in one colour) and the solution made with the eulerian method in another colour.
What i've done so far (Before reaching the limit of my capabilities!):
I've written this script:
% Eulerian Method
% Setup and initial conditions
h = 0.25; % step size
x = 0:h:5; % interval of x
y = zeros(size(x)); % allocate the resulting y
y(1) = 1; % inizial value of y
n = numel(y); % the number of y values
% The loop that solves the differential equation:
for i=1:n-1
f = (y(i)-2*sin(x(i)))
y(i+1) = y(i) + h * f;
end
And i've managed to plot it into a graph but i have no idea of how to complete the tasks properly.
Please Help!
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
