Borrar filtros
Borrar filtros

Euler's method code

1 visualización (últimos 30 días)
Mike Asmanis
Mike Asmanis el 18 de Jun. de 2021
Comentada: Mike Asmanis el 18 de Jun. de 2021
Hello , how can I code this : y'(t)=cos(t + y) y(0)=0 t[0,3] (exact solution y(t)=-t + 2arctan(t)) using Euler's method like the code below?
clc
clear all
close all
h=0.01;
N=100; % number of steps
y(1)=1;
for n=1:N
y(n+1)=y(n)+h*(-6*y(n));
x(n+1)=n*h;
end
plot(x,y)
hold on
x=0:0.01:1;
y=exp(-6*x); % exact solution
plot(x,y)

Respuestas (1)

Paul
Paul el 18 de Jun. de 2021
The code that is posted solves a differential equation of the form
y'(x) = f(x,y), y(0) = y0
and compares it to the exact solution
y(x) = some function of x
over the interval
x [0 1]
As it happens, your problem has the exact same form, with the independent variable being t instead of x and the endpoint of the interval is different.
  2 comentarios
Mike Asmanis
Mike Asmanis el 18 de Jun. de 2021
I know that it solves a different equation , i just need to solve my problem using a simillar or the exact code like the one i posted.
Mike Asmanis
Mike Asmanis el 18 de Jun. de 2021
I'm getting Array indices must be positive integers or logical values.

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by