Error when I run ODE45 function
Ältere Kommentare anzeigen
Could I know where I might be wrong in ode.m as I am getting following message as error when I run the ODE file. F1 and F2 are function of time.
Error using odearguments (line 93)
OUTPUT must return a column vector.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in Ode (line 11)
[t, x] = ode45(@Output,tspan,IC);
State space model: (Output.m)
function [sdot] = Output(t,x)
Ze = zeros(3);
I = eye(3);
M = [8070000,0,-629468070;0,8070000,112980;-629468070,112980,6.800000000000000e+10];
Ad = [8.053095218400001e+06,0,-4.831857131040000e+08;0,2.167940435676214e+05,0;-4.831857131040000e+08,0,3.865485704832000e+10];
C = [0,0,0;0,3.241885080000000e+05,0;0,0,1.301151158327999e+09];
Cm = [4.12e+04,0,-2.82e+06;0,1.19e+04,0;-2.82e6,0,3.11e+08];
MA = M+Ad;
Q = C+Cm;
Fwt = 2.793977550000000e+04; %Wind force on turbine tower
Fg = -79086000; %Gravitational force
Fbuoy = 7.844814740000000e+07; %Buoyancy force
Fp = 2.712318560000001e+06; %Heave force
Fmx = -334731.8545;
Fmz = -3517000;
t = 0:0.1:10
for i = 1:length(t)
Fh = hydro(t(i))
F1(1,i) = Fmx+27939.6+6.5*10^5+Fh(1,i);
F2(1,i) = Fmz+Fg+Fbuoy+Fp;
F3(1,i) = -112510430.2+3.44*10^6+266.5*10^5+(Fh(1,i)*18);
A = [Ze, I; -inv(MA)*Q, Ze];
B = [Ze; inv(MA)];
F = [F1;F2;F3];
Svec = [x(1);x(2);x(3);x(4);x(5);x(6)];
%
sdot = A*Svec + B*F;
end
end
ODE.m:
%Initial Condition
x(10) = 0; x(20) = 0; x(30) = 0;
x(40) = 0; x(50) = 0; x(60) = 0;
IC = [x(10);x(20);x(30);x(40);x(50);x(60)];
%time span
t0 = 0; tf = 10;
tspan = t0:0.1:tf;
[t, x] = ode45(@Output,tspan,IC);
IC = [IC;x(end)];
%x(1) = x(:,1);
%x(2) = x(:,2);
%x(3) = x(:,3);
%x(4) = x(:,4);
%x(5) = x(:,5);
%x(6) = x(:,6);
%Plot Results
figure(1), clf
plot(t,x(:,1)), xlabel('time(s)'), ylabel('surge(m)')
title ('Surge vs Time')
8 Kommentare
Star Strider
am 15 Jul. 2020
I cannot run your code:
Unrecognized function or variable 'hydro'.
Fh = hydro(t(i))
so I cannot check to see if ‘A’, ‘B’ and ‘F’ are matrices. If they are, ‘sdot’ will likely not be a column vector.
Satish Jawalageri
am 15 Jul. 2020
Bearbeitet: Satish Jawalageri
am 15 Jul. 2020
Star Strider
am 15 Jul. 2020
Before we go further with this, check to see if ‘A’, ‘B’ and ‘F’ are matrices. If they are, ‘sdot’ will likely not be a column vector.
The easiest way to do that is ether to add size calls without a closing semicolon so that they print to the Command Window, or just leave off the closing semicolon for ‘sdot’.
Satish Jawalageri
am 15 Jul. 2020
Star Strider
am 15 Jul. 2020
Those are not column vectors.
You will have to decide how best to solve that, since I have no idea what you are doing.
Satish Jawalageri
am 15 Jul. 2020
Walter Roberson
am 17 Jul. 2020
Why are you looping over time there? why not just process for the one time that was passed into the function? The processing for any one t in the loop does not appear to depend on previous iterations.
Satish Jawalageri
am 17 Jul. 2020
Antworten (1)
Gifari Zulkarnaen
am 16 Jul. 2020
0 Stimmen
You might see my example here to solve equation of motion using ODE:
2 Kommentare
Satish Jawalageri
am 16 Jul. 2020
Bearbeitet: Satish Jawalageri
am 16 Jul. 2020
Gifari Zulkarnaen
am 27 Jul. 2020
I have revised the file
Thank you for your notice
Kategorien
Mehr zu Programming finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!