Hello, I have divided first order differential equations into 6 systems over respective time span, I am getting result as Inputs must be floats, namely single or double. I have tried to correct but not happening. Please help

3 visualizzazioni (ultimi 30 giorni)
t1span=[0:0.5:pi]
t2span=[ pi:0.5:2*pi];
t3span=[ 2*pi:0.5:3*pi];
t4span=[3* pi:0.5:4*pi];
t5span=[4* pi:0.5:5*pi];
t6span=[5* pi:0.5:6*pi];
t=linspace(0,0.5,50)
Axis=[-30 100 -30 50]
x=linspace(-30,100,50)
x1= linspace(5.5,10.5,50)
x2= linspace(10,14,50)
t1span=[0:0.5:pi]
t2span=[ pi:0.5:2*pi];
t3span=[ 2*pi:0.5:3*pi];
t4span=[3* pi:0.5:4*pi];
t5span=[4* pi:0.5:5*pi];
t6span=[5* pi:0.5:6*pi];
t=linspace(0,0.5,50)
k1=2; k2=7; xT=44;yT=32;
xt=[ 2 7.18 12.77 17.53 20.87 28.68 ] ;
yt=[ 8 11.42 13.61 15.41 17.78 21.28 ];
q1=[q11;q21;q31]
q10=[2; 8 ;0]
%q20=[xt2 yt2 atan2(yt2-yt1,xt2-xt1)]
% q20=[xt2 yt2 0.5826]
q20=[ 7.1892; 11.4189 ;0.5826]
q2=[q12 ;q22; q32] ;
% q30=[xt3 yt3 atan2(yt3-yt2,xt3-xt2)]
% q30=[xt3 yt3 0.3750]
q30=[ 12.7734; 13.6167 ;0.3750]
q3=[q13; q23 ;q33];
% q40=[xt4 yt4 atan2(yt4-yt3,xt4-xt3)]
%q40=[xt4 yt4 0.3620]
q40=[17.522; 15.4147 ;0.3620]
q4=[q14; q24; q34];
%q50=[xt5 yt5 atan2(yt5-yt4,xt5-xt4)]
% q50=[xt5 yt5 0.5988]
q50=[21; 17.78; 0.5988]
q5=[q15; q25; q35];
%q60=[ xt6 yt6 atan2(yt6-yt5,xt6-xt5)]
%q60=[ xt6 yt6 0.4264]
q6=[q16; q26 ;q36];
q60= [28.6819 ; 21.2781 ;0.4264]
etheta31=atan2(32-8,44-2);
etheta32=atan2(32-11.42,44-7.18);
etheta33=atan2(32-13.61,44-12.77);
etheta34=atan2(32-15.41,44-17.52);
etheta35=atan2(32-17.78,44-21);
etheta36=atan2(32-21.28,44-28.68);
v11= -k1*(44-2)
v12= -k1*(44-7.18)
v13= -k1*(44-12.77)
v14= -k1*(44-17.53)
v15= -k1*(xT-20.87)
v16= -k1*(xT-28.86)
v21=-k2*(atan2(32-8,44-2)+0.2)+(32-8)*sin(t1)
v22=-k2*(atan2(32-11.42,44-7.18)-0.2)+(32-11.42)*sin(t2)
v23=-k2*(atan2(32-13.61,44-12.77)-0.2)+(32-13.61)*sin(t3)
v24=-k2*(atan2(32-15.41,44-17.52)-0.2)+(32-15.41)*sin(t4)
v25=-k2*(atan2(32-17.78,44-21)-0.2)+(32-17.78)*sin(t5)
v26=-k2*(atan2(32-21.28,44-28.68))+(32-21.28)*sin(t6)
dq11dt1=v11*cos(q31);
dq12dt2=v12*cos(q32);
dq13dt3=v13*cos(q33);
dq14dt4=v14*cos(q34);
dq15dt5=v15*cos(q35);
dq16dt6=v16*cos(q36);
dq21dt1= v11*sin(q31);
dq22dt2=v12*sin(q32);
dq23dt3=v13*sin(q33);
dq24dt4=v14*sin(q34);
dq25dt5=v15*sin(q35);
dq26dt6=v16*sin(q36);
dq31dt1= v21;
dq32dt2= v22;
dq33dt3= v23;
dq34dt4= v24;
dq35dt5= v25;
dq36dt6= v26;
t1span=[0:0.5:pi];
q1=[q11 q21 q31];
q10=[2 8 0];
F1=@(t1,q1)(vpa ([v11+v21*(32-8);-v21*(32-8);v21]));
[t1,q1] = ode45(F1,t1span,q10);
Plot (q11,q21)
hold on;
q2=[q12 q22 q32];
q20=[ 7.1892; 11.4189 ;0.5826]
t2span=[ pi:0.5:2*pi];
F2=@(t2,q2)(vpa([v12+v22*(32-11.42);-v22*(32-11.42);v22]));
[t2,q2] = ode45(F2,t2span,q20);
plot(q12,q22)
hold on;
q3=[q13 q23 q33];
q30=[ 12.7734; 13.6167 ;0.3750];
t3span=[2*pi:0.5:3*pi];
F3=@(t3,q3)(vpa([v13+v23*(32-13.61);-v23*(32-13.61);v23]));
[t3,q3] = ode45(F3,t3span,q30);
plot(q13,q23)
hold on;
q4=[q14 q24 q34];
q40=[17.522; 15.4147 ;0.3620];
t4span=[3*pi:0.5:4*pi];
[t4,q4] = ode45(F4,t4span,q40);
F4=@(t4,q4)(vpa([v14+v24*(32-15.41);-v24*(32-15.41);v24]));
plot(q14,q24)
hold on;
q5=[q15 q25 q35];
q50=[21; 17.78; 0.5988];
t5span=[4*pi:0.5:5*pi];
F5=@(t5,q5)(vpa([v15+v25*(32-17.78);-v25*(32-17.78);v25]));
[t5,q5] = ode45(F5,t5span,q50);
plot(q15,q25)
hold on;
q6=[q16 q26 q36];
q60= [28.6819 ; 21.2781 ;0.4264]
t6span=[5*pi:0.5:6*pi];
F6=@(t6,q6)(vpa([v16+v26*(32-21.28);-v22*(32-21.28);v26]));
[t6,q6] = ode45(F6,t6span,q60);
plot(q16,q26)
hold off;
end

Risposte (1)

Walter Roberson
Walter Roberson il 27 Ago 2018
Several of your variables are undefined, especially your t* and q* variables.
You have
F1=@(t1,q1)(vpa ([v11+v21*(32-8);-v21*(32-8);v21]));
vpa() returns a symbolic value even if the inputs are numeric. ode45() cannot work with symbolic values.
I suspect you have defined the q* variables and t* variables as symbolic. Please note that when you have equations along the line of
syms x
y = x^2;
F = @(x) y
then when F is evaluated, there is no connection made between the x of the input argument and the x that appears in the formula for y.
You should probably be creating your F1 by using
F1 = matlabFunction([v11+v21*(32-8);-v21*(32-8);v21], 'vars', [t1, q1])

Categorie

Scopri di più su Programming in Help Center e File Exchange

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by