I'm trying to solve a system of differential equations using Euler's method, but I don't know what the problem is with my code. If you can correct me the problem

2 visualizzazioni (ultimi 30 giorni)
clear
clc
clf
a= 0;
b= 2;
delta_x =0.5;
y1 (1) = 4;
y2 (1) = 6;
n= (b-a)/delta_x + 1 ;
x (1) = 0;
funcl =@(yl) - 0.5*yl ;
func2=@(y1, y2) 4 - 0.3* y2 - 0.1* yl ;
for i= 1:n-1
x(i+1)= i* delta_x;
y1 (i+1)= y1 (i) + delta_x * feval (funcl, yl (i));
y2 (i+1)= y2 (i)+ delta_x * feval (func2, y1 (i), y2 (i));
end
x
y1
y2
plot (x, y1, x, y2)
title('Plot of x va yi & y2 - Explicit Euler')
grid on

Risposta accettata

Alan Stevens
Alan Stevens il 24 Nov 2022
Don't confuse the number 1 with lower case l
a= 0;
b= 2;
delta_x =0.5;
y1(1) = 4;
y2(1) = 6;
n= (b-a)/delta_x + 1 ;
x(1) = 0;
func1 =@(yl) - 0.5*yl ;
func2=@(y1, y2) 4 - 0.3* y2 - 0.1* y1 ;
for i= 1:n-1
x(i+1)= i* delta_x;
y1(i+1)= y1(i) + delta_x * feval(func1,y1(i));
y2(i+1)= y2(i)+ delta_x * feval(func2, y1(i),y2(i));
end
plot (x, y1, x, y2)
title('Plot of x va yi & y2 - Explicit Euler')
grid on
  3 Commenti

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Statics and Dynamics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by