i am getting error in line 18 of invalid use of operator.please help me solving this

1 visualización (últimos 30 días)
clear all
close all
m1 =12000;
m2 =10000;
m3 =8000;
k1 =3000;
k2 =2400;
k3 =1800;
A =[( k1 + k2 )/ m1 - k2 / m1 0 ; - k2 / m2 ( k2 + k3 )/ m2 - k3 / m2 ; 0 - k3 / m3 k3 / m3 ];
[V , D ]= eig ( A );
omega = diag ( D ).^0.5
modes = V ;
modes (: ,1)= modes (: ,1)/ modes (3 ,1);
modes (: ,2)= modes (: ,2)/ modes (3 ,2);
modes (: ,3)= modes (: ,3)/ modes (3 ,3);
modes
figure (1);
subplot (1 ,3 ,1);
plot ([0; modes (:,1)] ,0:3 ,bo-);
ylabel ( Floor );
xlabel ( Relative Displacement );
mytitle = sprintf ( \\ omega =%.2 f rad / s ’ , omega (1));
title ( mytitle )
subplot (1 ,3 ,2);
plot ([0; modes (: ,2)] ,0:3 , bo - );
xlabel ( Relative Displacement );
mytitle = sprintf ( \\ omega =%.2 f rad / s ’ , omega (2));
title ( mytitle )
subplot (1 ,3 ,3);
plot ([0; modes (: ,3)] ,0:3 , bo - );
xlabel ( Relative Displacement );
mytitle = sprintf ( \\ omega =%.2 f rad / s ’ , omega (3));
title ( mytitle )
  2 comentarios
Bjorn Gustavsson
Bjorn Gustavsson el 15 de Abr. de 2021
When running your code it gives an error at:
[V , D ]= eig ( A );
Because A has become a 3 x 2 matrix. Fix that - and give us the error-message.

Iniciar sesión para comentar.

Respuesta aceptada

deepak mishra
deepak mishra el 15 de Abr. de 2021
Can you please change it Actually I have no knowledge of matlab I have to use it in my Web development project. Please help me
  2 comentarios
Bjorn Gustavsson
Bjorn Gustavsson el 15 de Abr. de 2021
Now you have accepted this comment/question of yours as the ANSWER to your problem. That will hide it from other people. First you'll have to "unaccept" this answer. Then start to look at each successive line of your code and inspect the results they produce. For example after assigning the matrix A using your code I get:
A =
0.2500 0
-0.2400 0.2400
-0.2250 0.2250
Is that consistent with your expectations?
deepak mishra
deepak mishra el 15 de Abr. de 2021
actually i want to use this code which i have attached .please help if you can.

Iniciar sesión para comentar.

Más respuestas (2)

Bjorn Gustavsson
Bjorn Gustavsson el 15 de Abr. de 2021
Editada: Bjorn Gustavsson el 15 de Abr. de 2021
OK, so you want to solve 3 coupled equations of motion for some harmonically varying solution. First you have to understand the physics, then the mathematics and then you can solve this numerically.
1, physics.
Eq of motion:
Harmonic solutions ->
For a number of coupled oscillators you get
Where A has to be n-by-n, where in your case n is 3.
Here you should be able to identify your first problem, since A becomes 3-by-2!
You should be able to figure out what goes wrong in your assignment of A, it has to do with the interpretation of which terms are added(or subtracted) together to form a matrix-element. To not have that happen you should insert , (commas) between to separate the matrix-elements on a row. This is a very treacherous error we all(?) encountered when starting to use matlab.
HTH

Jan
Jan el 15 de Abr. de 2021
Editada: Jan el 15 de Abr. de 2021
For me line 18 is:
subplot (1 ,3 ,1);
I do not see a problem here. But in the next line:
plot ([0; modes (:,1)] ,0:3 ,bo-);
% ^ ^
Use single quotes ' instead. Did you copy the code from a DOCX, PDF or from the net? Then the quotes are converted sometimes. You should see the problem in the syntax highlighting already.
Please care for posting a copy of the complete error message and do not let the reader guess or count, which line is failing.
Notes:
  • Omit the brute clearing header "clear all; close all". This is not useful, but teachers suggest it only, because their teachers had suggested it 20 years ago. This is "cargo cult programming" and a widespread programming anti-pattern.
  • sqrt(X) is faster than the power operation X.^0.5.

Categorías

Más información sobre Graphics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by