필터 지우기
필터 지우기

Coding Euler's Method!!

조회 수: 4 (최근 30일)
Sharif
Sharif 2014년 11월 8일
답변: Mohammad Abouali 2014년 11월 9일
Hello everyone so I am trying to code Euler's method to solve this matrix A and I can't figure it out. Here is my code so far:
k_AB = 0.4;
k_BC = 0.1;
k_CA = 0.4;
k_ba = 0.2;
k_cb = 0.45;
k_ac = 0.16;
A = [ (-k_AB - k_ac), k_ba, k_CA;
k_AB, (-k_BC - k_ba), k_cb;
k_ac, k_BC, (-k_CA - k_cb); ];
x0 = [1;0;0];
h = 0.1;
for t = 0:0.1:1
xNEW = x0 + h*(A*x0);
x0 = xNEW
end
x0 = [2;0;0];
It seems that my first step has the 3 correct values, but every step after that is incorrect. If anyone who is familiar with Euler's Explicit Method can help I'd be extremely grateful! I've been trying this for hours on my Friday night :(
So step size = 0.1, initial conditions = [1;0;0] from time interval 0:0.1:1
Any help works!
  댓글 수: 3
Sharif
Sharif 2014년 11월 8일
I tried solving it by hand and trust my hand-written answers more than my MATLAB code. And can you elaborate about what you said about the derivative of matrix A?
Sharif
Sharif 2014년 11월 9일
Anybody think they can help? :\

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

채택된 답변

Mohammad Abouali
Mohammad Abouali 2014년 11월 9일
Your code is correct. What is x0 = [2;0;0]; at the end though.
Here is a modified version of your code. It is modified in such a way that you plot the changes in time at the end for each element of x
clear;
clc;
close all;
k_AB = 0.4;
k_BC = 0.1;
k_CA = 0.4;
k_ba = 0.2;
k_cb = 0.45;
k_ac = 0.16;
A = [ (-k_AB - k_ac), k_ba, k_CA;
k_AB, (-k_BC - k_ba), k_cb;
k_ac, k_BC, (-k_CA - k_cb); ];
x(:,1) = [1;0;0];
h = 0.1;
t=0:h:1;
for i=2:numel(t)
x(:,i) = x(:,i-1) + h*(A*x(:,i-1));
end
plot(t,x(1,:),'b')
hold on
plot(t,x(2,:),'r')
plot(t,x(3,:),'k')
xlabel('Time')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Desktop에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by