Solving for a symbol and converting it to double to use in a loop
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
My two questions are commented in the code by %question
% This program use Cramer's rule to solve the no damping case
clear all
close all
keq = 5.88e7; % equivalent spring constant cantilever beam
meq = 64.47; % equivalent mass cantilever beam
mb = 852.987; % mass of the body
syms w; % set w as a symbol
A = [keq + (keq*meq)/mb - w^2*meq, (keq*meq)/mb, (keq*meq)/mb, (keq*meq)/mb
(keq*meq)/mb, keq + (keq*meq)/mb - w^2*meq, (keq*meq)/mb, (keq*meq)/mb
(keq*meq)/mb, (keq*meq)/mb, keq + (keq*meq)/mb - w^2*meq, (keq*meq)/mb
(keq*meq)/mb, (keq*meq)/mb, (keq*meq)/mb, keq + (keq*meq)/mb - w^2*meq
];
adet = det(A); % determinant of A
*% I would like to solve for adet = 0 and store the positive solutions in W*
x = sym(ones(4, 1)); % pre-allocating x
% forcing vector with amplitude the same and a phase offshift
F = [0.01*exp(1i*pi/18), 0.01*exp(1i*pi/19), 0.01*exp(1i*pi/20), ...
0.01*exp(1i*pi/21)]';
M = zeros(4, 2); % pre-allocating M
*% I would then like to loop of each W(i) in W but I am not sure how to do this*
for k = 1:4
C = A;
C(:, k) = F;
x(k, 1) = det(C)/adet;
end
0 comentarios
Respuestas (1)
Roger Stafford
el 9 de Dic. de 2014
Cramer's Rule is not what you need to solve for w! Setting your determinant to zero will give you an eighth degree polynomial equation, and to solve it for w, you need to use either 'roots' or 'solve'. There will in general be eight roots, though some of them may be complex-valued. With either function you will need to specify the numeric value of your three parameters, just as you have done in your code.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!