# how to solve non linear simultaneous ordinary differential equation?

2 views (last 30 days)
Meenakshi Tripathi on 25 Mar 2021
Commented: Jan on 25 Nov 2021 = (35)(y − x) = (-7)x − xz + (28)y = xy − (2.97)z
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?

Jan on 25 Mar 2021
Edited: Jan on 25 Mar 2021
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.
Jan on 25 Nov 2021
You find an example for implementing your equation in Matlab. The elements of y are [A,B,C,D] in your case.