For example, I have to solve the following equations
if true syms x(t) y(t) z(t) eq1 = diff(x,t) == -x+3z; eq2 = diff(y,t) == -y+2z; eq3 = diff(z,t) == x^2-2z;end
I can use ode45.
if true f = @(t,x) [-x(1)+3*x(3);-x(2)+2*x(3);x(1)^2-2*x(3)]; [t,xa] = ode45(f,[0 1.5],[0 1/2 3]);end
Is there any way I can generate the following line automatically from the equations I get(they are symbolic).
f = @(t,x) [-x(1)+3*x(3);-x(2)+2*x(3);x(1)^2-2*x(3)];
In my case, the equation is generated inside the code, so I don't know the coefficients beforehand to write that line.
Best Answer