how to solve non linear simultaneous ordinary differential equation?
조회 수: 3 (최근 30일)
이전 댓글 표시
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/562726/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/562731/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/562736/image.png)
I solved this problem using ode23 like this-
function dydt = odefcn(t,y)
dydt = zeros(3,1);
dydt(1) = 35*y(2)- 35*y(1)
dydt(2) = (-7)*y(1)-y(1)*y(3)+28*y(1)
dydt(3) = y(1)*y(2)-(2.97)*y(3)
tspan = [0 5]
y0 = [1 0 1]
[t,y] = ode23(@(t,y) odefcn(t,y), tspan, y0)
The error that i am getting is-
Not enough input arguments.
Error in odefcn (line 3)
dydt(1) = 35*y(2)- 35*y(1)
Is it the right way of solving above problem?
댓글 수: 0
채택된 답변
Jan
2021년 3월 25일
편집: Jan
2021년 3월 25일
How did you call the function? Using the green triangle in the editor? Then no inputs are provided.
The posted code consists of two parts, but it looks, like you have inserted in in one m-file. A sorted version:
function main
tspan = [0 5];
y0 = [1 0 1];
[t, y] = ode23(@odefcn, tspan, y0);
plot(t, y);
end
function dydt = odefcn(t,y)
dydt = zeros(3,1);
dydt(1) = 35 * y(2) - 35 * y(1);
dydt(2) = -7 * y(1) - y(1) * y(3) + 28 * y(1);
dydt(3) = y(1) * y(2) - 2.97 * y(3);
end
To improve the readability I've inserted spaces around the operators.
@(t,y) odefcn(t,y) can be abbreviated to @odefcn.
댓글 수: 7
Fadzai Zonke
2021년 11월 24일
It is a different question, somthing similiar
I have 4 non linear differential equations:
for example
dA/dt = 7 - 3*A + 4*T*A
dB/dt = 9 - 4*B + 2*B/A - 5*D*(2-B)
dC/dt = 2- C + 3*B/4
dD/dt = 6 - A/4 - D/3
t = linspace[0 300]
I need to solve them and plot a grapgh for each Variable against t (A,t),(B,t),(C,t),(D,t)
Jan
2021년 11월 25일
You find an example for implementing your equation in Matlab. The elements of y are [A,B,C,D] in your case.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!