Cant get the equation to work

clc
num_values=11;
first_val=0;
time=zeros(1,num_values);
z(1)=first_val;
s=zeros(1,11);
time(1)=first_val;
t=sym('t');
TU(1)=5*pi/180;
TU(2)=7*pi/180;
TU(3)=6*pi/180;
TU(4)=9*pi/180;
TU(5)=12*pi/180;
TU(6)=17*pi/180;
TU(7)=19*pi/180;
TU(8)=27*pi/180;
TU(9)=33*pi/180;
TU(10)=36*pi/180;
TU(11)=45*pi/180;
for n=2:11
time(n)=(n-1)*15;
z(n)=(-z(n-1)+((2*(TU(n)-TU(n-1)))/(time(n)-time(n-1))));
sprintf('z= %.05f \n',z)
end
for n=2:10;
s(n)=((z(n)-z(n-1))/(2*(time(n)-time(n-1)))) * ((t-time(n-1)).^2) + z(n-1)*(t-time(n-1))+TU(n-1);
end
Im trying to get the values from the equation with s using the values of the equation with z and i dont know how. In the workspaces it says that s is a 1x11 matrix but i think it should be 1x10

4 comentarios

KSSV
KSSV el 28 de Nov. de 2018
You have initiated s as zeros(1,11);....so according to your code..it is correct.
KSSV
KSSV el 28 de Nov. de 2018
YOu can replace the array TU with the following:
TU = [5 7 6 9 12 17 19 27 33 36 45]*pi/180;
Clara Ghattas
Clara Ghattas el 28 de Nov. de 2018
even then, it says that the left and right sides have different number if elements so it cant work
Jan
Jan el 28 de Nov. de 2018
"it says" - who is it? Please post the complete error message, such that the readers do not have to guess, which line fails with which message.

Respuestas (1)

Areej Varamban Kallan
Areej Varamban Kallan el 7 de Dic. de 2018
Editada: Areej Varamban Kallan el 7 de Dic. de 2018

0 votos

Hi Clara,
I have executed your code and the error message I get is "Unable to convert expression into double array". The variable 's' is defined to be a double matrix and the variable 't' is defined to be a symbolic variable. In the second for loop you are doing certain computations using the symbolic variable 't'. The results of such computations will be of symbolic type. As a result your code is attempting to assign a symbolic value to a double matrix. This is not valid.
Please redine s as:
s=sym(zeros(1,11));

La pregunta está cerrada.

Etiquetas

Preguntada:

el 28 de Nov. de 2018

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by