hello, i want to set the final values of the first function with variable "u" as an initial values for the second function with variable "uc", which can be shown below. my main problem is this term "uc0 = u[end end end end];" what is the correct way.

1 次查看(过去 30 天)
close all; clc
kd = 10;
cd = 0.0051;
ct = 10.47;
Tt = 39.5671;
Jt = 13.92;
Jb = 1.1378;
WOB = 1760.9718;
Ls = 0.00597;
Lk = 0.0045;
Ld = 0.183;
Lstr = 0.000019312;
u0 = [0 0 0 0];
tspan = [0 45];
[t,u] = ode45(@(t,u) first_order2(u,kd,cd,ct,Tt,Jt,Jb,WOB,Ls,Lk,Ld,Lstr), tspan, u0);
plot(t,u(:,2),'r',t,u(:,4),'b')
figure
plot(u(:,3)-u(:,1),u(:,4),'g')
%CONTROL
uc0 = u[end end end end];
[tc,uc] = ode45(@(tc,uc) control(uc,kd,cd,ct,Tt,Jt,Jb,WOB,Ls,Lk,Ld,Lstr), tspan, uc0);
plot(t,uc(:,2),'r',t,uc(:,4),'b')
figure
plot(uc(:,3)-uc(:,1),uc(:,4),'g')

采纳的回答

Torsten
Torsten 2018-7-3
uc0 = u(end,:);
  3 个评论
Torsten
Torsten 2018-7-6
编辑:Torsten 2018-7-6
The parameter lists for "control" do not fit:
[tc,uc] = ode45(@(tc,uc) control(uc,kd,cd,ct,Tt,Jt,Jb,WOB,Ls,Lk,Ld,Lstr), tspan, uc0);
gives 12 arguments
function duc = control(tc,uc,kd,cd,ct,Jt,Jb,WOB,Ls,Lk,Ld,Lstr,L,wd)
gives 14 arguments.
Stephen23
Stephen23 2018-7-6
@Dirar Aletan: rather than trying to pass so many individual variables, I would recommend that you define those values as fields of one structure. Then you just have one variable to pass around.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by