I've been trying to solve a set of 4 coupled differential equations that are pretty nasty and then plot solutions. I keep getting errors when using ode45 to solve the system. Here's the important code:
g=9.8; l1=1; l2=1; m1=1; m2=1;diffeq = @(t,y,g,m1,m2,l1,l2) [eq1;eq2;eq3;eq4];odeWrapper = @(t,y) diffeq(t,y,g,m1,m2,l1,l2);[t,yi] = ode45(odeWrapper,[0,1],[45,0,0,0]);plot(t,yi(:,1));
I'm not going to bother to actually type out the equations I put into diffeq because they're ridiculously long, but I have checked to make sure parentheses match up correctly and stuff like that.
I keep getting the same error saying I have too many input arguments to the ode function:
Error usingode>@(t,y)[(l2*y(3)-l1*y(4)*cos(y(1)-y(2)))/((l1^2)*l2*(m1+m2*(sin(y(1)-y(2))^2)));(l1*(m1+m2)*y(4)-l2*m2*y(3)*cos(y(1)-y(2)))/(l1*(l2^2)*m2*(m1+m2*(sin(y(1)-y(2))^2)));-(m1+m2)*g*l1*sin(y(1))-((y(3)*y(4)*sin(y(1)-y(2)))/(l1*l2(m1+m2*(sin(y(1)-y(2))^2))))+(((l2^2)*m2*(y(3)^2)+(l1^2)*(m1+m2)*(y(4)^2)-l1*l2*m2*y(3)*y(4)*cos(y(1)-y(2)))*sin(2*(y(1)-y(2))))/(2*(l1^2)*(l2^2)*(m1+m2*(sin(y(1)-y(2))^2))^2);-m2*g*l2*sin(y(2))+((y(3)*y(4)*sin(y(1)-y(2)))/(l1*l2(m1+m2*(sin(y(1)-y(2))^2))))-(((l2^2)*m2*(y(3)^2)+(l1^2)*(m1+m2)*(y(4)^2)-l1*l2*m2*y(3)*y(4)*cos(y(1)-y(2)))*sin(2*(y(1)-y(2))))/(2*(l1^2)*(l2^2)*(m1+m2*(sin(y(1)-y(2))^2))^2)] Too many input arguments. Error in ode>@(t,y)diffeq(t,y,g,m1,m2,l1,l2) Error in odearguments (line 90) f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115) odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin); Error in ode (line 30) [t,yi] = ode45(@(t,y) diffeq(t,y,g,m1,m2,l1,l2),[0,1],[1,0,0,0]);
Any help would be much appreciated as I need this to work for a paper that is due soon!
Best Answer