math - Solving Differential equations in Matlab, ode45 -
i'm trying solve system 3 differential equations function ode45 in matlab. not understand errors getting , use understanding im doing wrong.
the differential equations following:
f1 = -k1y1+k2(y2-y1) f2 = -k2(y2-y1)+k3(y3-y2) f3 = -k3(y3-y2)
and code in matlab this:
function dz = kopplad(t, z) global m1 m2 m3 k1 k2 k3 dz = [z(2) -k1*z(1)/m1 + k2*(z(2)-z(1))/m1 z(4) -k2*(z(2)-z(1))+k3(z(3)-z(2))/m2 z(6) -k3(z(3)-z(2))/m3]; global m1 m2 m3 k1 k2 k3 m1 = 0.75; m2 = 0.40; m3 = 0.65; k1 = 0.85; k2 = 1.1; k3 = 2.7; [t, z] = ode45(@kopplad, [0, 50], [0 -1 0 1 0 0]); plot(t, z(:,1)) hold on plot(t,z(:,3),'--') plot(t,z(:,5),'*') legend('y_1', 'y_2', 'y_3'); hold off
the errors i'm recieving following:
attempted access
k3(1.00002)
; index must positive integer or logical.error in
kopplad (line 3) dz = [z(2)
error in ode45 (line 262)
f(:,2) = feval(odefcn,t+ha(1),y+f*hb(:,1),odeargs{:});
error in diffekv (line 6)
[t, z] = ode45(@kopplad, [0, 50], [0 -1 0 1 0 0]);
a while passed since did matlab programming, far remember, should pass variables function, i.e. write @(x,y)kopplad(x,y)
, if understand code in correct way. if rest (global variables , equations) correct, shall fine.
Comments
Post a Comment