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 (최근 30일)
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

채택된 답변

Alan Stevens
Alan Stevens 2022년 11월 24일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Statics and Dynamics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by