Info

此问题已关闭。 请重新打开它进行编辑或回答。

If I try to solve ODE45 for the following, I am getting msg"Inputs must be floats, namely single or double. Can anybody tell me how to rectify? I am new to Matlab

3 次查看(过去 30 天)
for j=1:20 ;
syms r xT yT k1 k2 t p v q q1 q2 q3 q10 q20 xt yt Px Py Ox Oy RD RP PD fcr fct fcrx fcry fctx fcty fct fcr FCTX FCTY FCRX FCRY Fx Fy v beta
q=[q1 q2 q3];
xt=([ 2 7.18 12.77 17.52 21 28.68 31 33.96 33.15 33 33 33 33 33 33 33 33 33 32.73 44]) ;
yt=([ 8 11.42 13.61 15.41 17.78 21.28 22.33 25.74 25.47 25.06 25.31 25.23 25.26 25.4 25.2 25.4 25.4 25.20 25.27 32]) ;
A(1,j) = (yT-yt(1,j));
B(1,j)=(xt(1,j)-xT);
C(1,j)= -(yt(1,j)*xT+xt(1,j)*yT);
q=[q1 q2 q3];
q0(1)=2; q0(2)=8;q0(3)=0;
tspan =[0 2*pi];
%q0=[2 8 0];
k1=2; k2=7;
xT=44; yT= 32; fct=2; fcr=1
r=sqrt((44-q1).^2+ (32-q2).^2);
dsqr(1,j) = ((xt(1,j) - q1).^2 + (yt(1,j) - q2).^2);
dsqr(1,1) = ((xt(1,1) - q1).^2 + (yt(1,1) - q2).^2);
dsqr(1,2) = ((xt(1,2) - q1).^2 + (yt(1,2) - q2).^2);
dsqr(1,3) = ((xt(1,3) - q1).^2 + (yt(1,3) - q2).^2);
dsqr(1,4) = ((xt(1,4) - q1).^2 + (yt(1,4) - q2).^2);
dsqr(1,5) = ((xt(1,5) - q1).^2 + (yt(1,5) - q2).^2);
dsqr(1,6) = ((xt(1,6) - q1).^2 + (yt(1,6) - q2).^2);
dsqr(1,7) = ((xt(1,7) - q1).^2 + (yt(1,7) - q2).^2);
dsqr(1,8) = ((xt(1,8) - q1).^2 + (yt(1,8) - q2).^2);
dsqr(1,9) = ((xt(1,9) - q1).^2 + (yt(1,9) - q2).^2);
dsqr(1,10) = ((xt(1,10) - q1).^2 + (yt(1,10) - q2).^2);
dsqr(1,11) = ((xt(1,11) - q1).^2 + (yt(1,11) - q2).^2);
dsqr(1,12) = ((xt(1,12) - q1).^2 + (yt(1,12) - q2).^2);
dsqr(1,13) = ((xt(1,13) - q1).^2 + (yt(1,13) - q2).^2);
dsqr(1,14) = ((xt(1,14) - q1).^2 + (yt(1,14) - q2).^2);
dsqr(1,15) = ((xt(1,15) - q1).^2 + (yt(1,15) - q2).^2);
dsqr(1,16) = ((xt(1,16) - q1).^2 + (yt(1,16) - q2).^2);
dsqr(1,17) = ((xt(1,17) - q1).^2 + (yt(1,17) - q2).^2);
dsqr(1,18) = ((xt(1,18) - q1).^2 + (yt(1,18) - q2).^2);
dsqr(1,19) = ((xt(1,19) - q1).^2 + (yt(1,19) - q2).^2);
p(1,j) = fcr/(dsqr(1,j).^3/2); fcrx(1,j) = p*((xt(1,j)) - q1); fcry(1,j) = p*((yt(1,j)) - q2);
fcrx(1,1)=fcr/(dsqr(1,1).^3/2)*((xt(1,1)) - q1); fcrx(1,2)=fcr/(dsqr(1,2).^3/2)*((xt(1,2)) - q1); fcrx(1,3)=fcr/(dsqr(1,3).^3/2)*((xt(1,3)) - q1); fcrx(1,4)=fcr/(dsqr(1,4).^3/2)*((xt(1,4)) - q1); fcrx(1,5)=fcr/(dsqr(1,5).^3/2)*((xt(1,5)) - q1); fcrx(1,6)=fcr/(dsqr(1,6).^3/2)*((xt(1,6)) - q1); fcrx(1,7)=fcr/(dsqr(1,7).^3/2)*((xt(1,7)) - q1); fcrx(1,8)=fcr/(dsqr(1,8).^3/2)*((xt(1,8)) - q1); fcrx(1,9)=fcr/(dsqr(1,9).^3/2)*((xt(1,9)) - q1); fcrx(1,10)=fcr/(dsqr(1,10).^3/2)*((xt(1,10))-q1); fcrx(1,11)=fcr/(dsqr(1,11).^3/2)*((xt(1,11)) - q1); fcrx(1,12)=fcr/(dsqr(1,12).^3/2)*((xt(1,12)) - q1); fcrx(1,13)=fcr/(dsqr(1,13).^3/2)*((xt(1,13)) - q1); fcrx(1,14)=fcr/(dsqr(1,14).^3/2)*((xt(1,14)) - q1); fcrx(1,15)=fcr/(dsqr(1,15).^3/2)*((xt(1,15)) - q1); fcrx(1,16)=fcr/(dsqr(1,16).^3/2)*((xt(1,16)) - q1); fcrx(1,17)=fcr/(dsqr(1,17).^3/2)*((xt(1,17)) - q1); fcrx(1,18)=fcr/(dsqr(1,18).^3/2)*((xt(1,18)) - q1); fcrx(1,19)=fcr/(dsqr(1,19).^3/2)*((xt(1,19)) - q1);
fcry(1,1) = fcr/(dsqr(1,1).^3/2)*((yt(1,1)) - q2); fcry(1,2) = fcr/(dsqr(1,2).^3/2)*((yt(1,2)) - q2); fcry(1,3) = fcr/(dsqr(1,3).^3/2)*((yt(1,3)) - q2); fcry(1,4) = fcr/(dsqr(1,4).^3/2)*((yt(1,4)) - q2); fcry(1,5) = fcr/(dsqr(1,5).^3/2)*((yt(1,5)) - q2); fcry(1,6) = fcr/(dsqr(1,6).^3/2)*((yt(1,6)) - q2); fcry(1,7) = fcr/(dsqr(1,7).^3/2)*((yt(1,7)) - q2); fcry(1,8) = fcr/(dsqr(1,8).^3/2)*((yt(1,8)) - q2); fcry(1,9) = fcr/(dsqr(1,9).^3/2)*((yt(1,9)) - q2); fcry(1,10) = fcr/(dsqr(1,10).^3/2)*((yt(1,10)) - q2); fcry(1,11) = fcr/(dsqr(1,11).^3/2)*((yt(1,11)) - q2); fcry(1,12) = fcr/(dsqr(1,12).^3/2)*((yt(1,12)) - q2); fcry(1,13) = fcr/(dsqr(1,13).^3/2)*((yt(1,13)) - q2); fcry(1,14) = fcr/(dsqr(1,14).^3/2)*((yt(1,14)) - q2); fcry(1,15) = fcr/(dsqr(1,15).^3/2)*((yt(1,15)) - q2); fcry(1,16) = fcr/(dsqr(1,16).^3/2)*((yt(1,16)) - q2); fcry(1,17) = fcr/(dsqr(1,17).^3/2)*((yt(1,17)) - q2); fcry(1,18) = fcr/(dsqr(1,18).^3/2)*((yt(1,18)) - q2); fcry(1,19) = fcr/(dsqr(1,19).^3/2)*((yt(1,19)) - q2);
fctx= (fct*(44 - q1))/r fcty= (fct*(32-q2))/r
Fx=fctx - (fcrx(1,1)+ fcrx(1,2)+ fcrx(1,3)+fcrx(1,4) +fcrx(1,5)+fcrx(1,6)+fcrx(1,7)+fcrx(1,8)+fcrx(1,9)+fcrx(1,10)+fcrx(1,11)+fcrx(1,12)+fcrx(1,13)+fcrx(1,14)+fcrx(1,15)+fcrx(1,16)+fcrx(1,17)+fcrx(1,18)+fcrx(1,19));
Fy=fcty -(fcry(1,1)+ fcry(1,2)+ fcry(1,3)+fcry(1,4) +fcry(1,5)+fcry(1,6)+fcry(1,7)+fcry(1,8)+fcry(1,9)+fcry(1,10)+fcry(1,11)+fcry(1,12)+fcry(1,13)+fcry(1,14)+fcry(1,15)+fcry(1,16)+fcry(1,17)+fcry(1,18)+fcry(1,19));
v= - k1 *sqrt(Fx.^2+Fy.^2);
dqdt(1)=v*cos(q3); dqdt(2)=v*sin(q3); dqdt(3)=beta-q3; dqdt=[dqdt(1);dqdt(2); dqdt(3)]; F=@(t,q)[v*cos(q3);v*sin(q3);-k2*(beta-q3)*t] ; F = @(t,q)[-k1*sqrt(Fx.^2+Fy.^2)*cos(q3);-k1*sqrt(Fx.^2+Fy.^2)*sin(q3);-k2*(beta-q3)*t];
[t,q] = ode45(F,[0 20*pi],[2 8 0]);
plot(q(1,1),q(1,2))
hold off
end

回答(1 个)

Bjorn Gustavsson
Bjorn Gustavsson 2018-8-14
The ode-suite (ode45, ode23,...) are intended to numerically integrate ordinary differential equations, you seem to feed ode45 a symbolic expression. For solving symbolic ODEs you have dsolve, perhaps that works. Otherwise you should write yourself a m-function describing your ODE, where the the function returns a column array with DyDt (doubles, preferably).
HTH

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by