This is my code
t=0:.1:5;
u(1:25)=.1;
u(26:51)=-.1;
plot(t,u);
[to,yo]=sim('hw3',5,[],[t',u']);
%Finding u_final and cost
l_b=ones(51,1)*(-50);
u_b=ones(51,1)*50;
options=optimset('Display','iter','PlotFcns','optimplotx');
[u_final,cost]=fmincon('find_cost',u,[],[],[],[],l_b,u_b,'find_constraint',options);
[t_f,x_f,y_f]=sim('hw3',5,[],[t' u_final']);
figure(3);
subplot(t_f,y_f(:,1));
grid;
xlabel('Time');
ylabel('Position');
figure(4);
subplot(t_f,y_f(:,2));
grid;
xlabel('Time');
ylabel('Velocity');
figure(5);
subplot(t_f,y_f(:,3));
grid;
xlabel('Time');
ylabel('Acceleration');
figure(6);
subplot(t_f,y_f(:,4));
grid;
xlabel('Time');
ylabel('Jerk');
figure(7);
subplot(t_f,y_f(:,5));
grid;
xlabel('Time');
ylabel('Jounce');
Every time i run the code it says Vectors must be of same length.
u and t should be of same size. Please help

6 comentarios

Image Analyst
Image Analyst el 23 de Feb. de 2018
I can't run it. Says
To use 'sim', at least one of the following products must be licensed, installed, and enabled:
Model Predictive Control Toolbox
Neural Network Toolbox
Simulink
System Identification Toolbox
Error in test5 (line 5)
[to,yo]=sim('hw3',5,[],[t',u']);
You forgot to list what products are needed on the right of this page. Please do so.
So, exactly what are your u and t, and why aren't they the same size?
KSSV
KSSV el 23 de Feb. de 2018
Which line you get error? It has some input file hw3
Aishwarya Bangalore Kumar
Aishwarya Bangalore Kumar el 23 de Feb. de 2018
'hw3' is a simulink model. sim is a form of communication between matlab and simulink. I m getting the error in line 4
plot(t,u)
They are time and state of a function respectively
KSSV
KSSV el 23 de Feb. de 2018
t=0:.1:5;
u(1:25)=.1;
u(26:51)=-.1;
plot(t,u);
The above is working fine....t and u are vectors of size 1X51.
Aishwarya Bangalore Kumar
Aishwarya Bangalore Kumar el 23 de Feb. de 2018
I am still getting the same error
Aishwarya Bangalore Kumar
Aishwarya Bangalore Kumar el 23 de Feb. de 2018
I understood sir thank you

Iniciar sesión para comentar.

Respuestas (1)

KSSV
KSSV el 23 de Feb. de 2018

0 votos

Use this:
t=0:.1:5;
u = zeros(size(t)) ;
u(1:round(length(t)/2))=.1;
u(round(length(t)/2)+1:end)=-.1;
plot(t,u);

Categorías

Más información sobre Deep Learning Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 23 de Feb. de 2018

Comentada:

el 23 de Feb. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by