solve ode with parametrizing function
20 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
hello i want to solve ode45
function x= teliko(R32y,F43x,R32x,F43y,R12y,F32x,F32y,a3,R23,w3,th3,R23y,R23x,R12x,R12,T12,m2,m3,Ig2,Time)
tspan=[0 0.5]; % set time interval
x0=[0 2 ]; % set initial conditions
[t,x] = ode45(@(t,x) for_kine(R32y,F43x,R32x,F43y,R12y,F32x,F32y,a3,R23,w3,th3,R23y,R23x,R12x,R12,T12,m2,m3,Ig2,Time),tspan,x0);
plot(t,x(:,1))
end
function dzdt = for_kine(t,x, R32y,F43x,R32x,F43y,R12y,F32x,F32y,a3,R23,w3,th3,R23y,R23x,R12x,R12,T12,m2,m3,Ig2,Time)
x1=x(1);
x2=x(2);
T12__=interp1(T12,Time,t);
R12_=interp1(R12,Time,t);
R12x_=interp1(R12x,Time,t);
f12=0;
f14=rad2deg(56.4);
f23=0;
R23x_=interp1(R23x,Time,t);
R23y_=interp1(R23y,Time,t);
w3_=interp1(w3,Time,t);
th3_=interp1(th3,Time,t);
R23_=interp1(R23,Time,t);
a3_=interp1(a3,Time,t);
F32y_=interp1(F32y,Time,t);
F32x=interp1(F32x,Time,t);
R12y_=interp1(R12y,Time,t);
F43y_=interp1(F43y,Time,t);
R32x_=interp1(R32x,Time,t);
F43x_=interp1(F43x,Time,t);
R32y_=interp1(R32y,Time,t);
dzdt = [x(2) ; [x(2)^2*[R12_*m2*[-R12x_*sin(x(1)+f12)+R12y_*cos(x(1)+f12)]+a*m3*[-R23x_*sin(x(1))+R23y_*cos(x(1))]] +...
w3_^2*[R23_*m3*[-R23x_*sin(th3_+f23)+R23y_*cos(th3_+f23)]]+...
a3_*[R23_*m3*[R23x_*sin(th3_+f23)+R23y_*cos(th3_+f23)]]+...
[-F32y]*R12x_+[F32x_]*R12y_+[-F43y_-Fpy]*R32x_+[F43x_+Fpx]*R32y_+T12__]/[Ig2-[R12_*m2*[cos(x(1)+f12)*R12x_+R12y_*sin(x(1)+f12)]+m3*a*[-R32x_*cos(x(1))+R32y_*sin(x(1))]]];];
end
and i get error not enough arguments at T12__=interp1(T12,Time,t);
T12 and time are 1*1001 vector
i think that T12 and Time are not inserted into the function
0 Kommentare
Antworten (1)
Steven Lord
am 22 Nov. 2019
The anonymous function you pass into ode45 accepts t and x from ode45 but does not pass them into your for_kine function.
@(t,x) for_kine(R32y,F43x,R32x,F43y,R12y,F32x,F32y,a3,R23,w3,th3,R23y,R23x,R12x,R12,T12,m2,m3,Ig2,Time)
However, your for_kine function does expect t and x to be passed into it as the first two inputs. This means the parameter R32y that the anonymous function passes into for_kine is being treated as t, F43x as x, R32x as R32y, etc. The last parameter the anonymous function passes into for_kine, Time, is being treated by for_kine as m3. Ig2 and Time aren't assigned values and so don't exist in the workspace of for_kine when you call it.
function dzdt = for_kine(t,x, R32y,F43x,R32x,F43y,R12y,F32x,F32y,a3,R23,w3,th3,R23y,R23x,R12x,R12,T12,m2,m3,Ig2,Time)
Modify your anonymous function so it passes t and x into for_kine. You may also want to package those additional parameters into a struct array so you only have to pass one parameter rather than twenty, something like this:
p = struct();
p.R32y = R32y;
p.F43x = F43x;
% etc
[t, x] = ode45(@(t, x) for_kine(t, x, p), ...
function dzdt = for_kine(t,x, p)
% Compute using t, x, p.R32y, etc. in here
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!