for loop iteration and solve command

3 visualizaciones (últimos 30 días)
Aamna Alshehhi
Aamna Alshehhi el 3 de Nov. de 2019
Comentada: Walter Roberson el 3 de Nov. de 2019
I face a problem in making a matrices, i just wanna make all variable in a martices as shown below. but errors keep showing.
also i cant get sloutions for Om2 Om3 Om4 , Al2 ,Al3 Al4 although i wrote al equations correctoly.
any suggestio?
% Parameters:
L1=1.8;
L3=2.4;
L2=2.2;
L4=2.7;
L1_2=1.18;
L2_2=0.467;
Th1= 134;
Th1_2=142.5;
% for t:0.1:10 , LA input,
% your solution steps etc.
%solution for ThA and Th2
for t=0:0.1:10
LA(:,(t/0.1+1)) = 1.15-(0.0362*t);
end
Z = L1_2*exp(1i*deg2rad(Th1_2));
Zc = conj(Z);
Ka = -LA.*Zc ; Kb = Z*Zc + LA.^2 -L2_2^2; Kc = -LA.*Z;
R = roots([Ka Kb Kc]);
F =(Z-(LA.*R))/L2_2;
ThA= rad2deg(angle(R));
Th2= rad2deg(angle(F));
%solution for Th3 and Th4
Z2=L1*exp(1i*deg2rad(Th1))- L2*exp(1i*deg2rad(Th2));
Zc2=conj(Z2);
Kd = -L4.*Zc2 ; Ke = Z2.*Zc2+L4.^2-L3.^2 ; Kf = -L4.*Z2;
T = roots([ Kd Ke Kf]);
S =((L4*T)-Z2)/L3;
Th4= rad2deg(angle(T));
Th3= rad2deg(angle(S));
%Parameters
syms L1 L2 L3 L4 L1_2 L2_2 Th1 Th1_2 integer
% variables and their derivatives
syms LA Th2 Om2 Al2 Th3 Om3 Al3 Th4 Om4 Al4 ThA OmA AlA integer
%loop eqn.
L_eqn1 = L2_2*exp(1i*Th2)+LA*exp(1i*ThA) -L1_2*exp(1i*Th1_2)==0;
L_eqn2 = L2*exp(1i*Th2)-L3*exp(1i*Th3)+L4*exp(1i*Th4) -L1*exp(1i*Th1)==0;
%velocity eqn for Om2 and OmA.
dL_eqn1 = diff(L_eqn1,Th2)*Om2 +diff(L_eqn1,ThA)*OmA+ diff(LA,t);
real_vel_eqn1 = real(dL_eqn1);
imag_vel_eqn1 = imag(dL_eqn1);
[Om2, OmA]=solve (real_vel_eqn1, imag_vel_eqn1);
%velocity eqn for Om3 and Om4.
dL_eqn2 = diff(L_eqn2,Th2)*Om2 -diff(L_eqn2,Th3)*Om3 +diff(L_eqn2,Th4)*Om4;
real_vel_eqn2 = real(dL_eqn2);
imag_vel_eqn2 = imag(dL_eqn2);
[Om3, Om4]=solve (real_vel_eqn2, imag_vel_eqn2);
%acceleration eqn for Al2 and AlA.
ddL_eqn1 = diff(dL_eqn1,Th2)*Om2 +diff(dL_eqn1,Om2)*Al2 + diff(dL_eqn1,ThA)*OmA +diff(dL_eqn1,OmA)*AlA;
real_acc_eqn1 = real(ddL_eqn1);
imag_acc_eqn1 = imag(ddL_eqn1);
[Al2, AlA]=solve (real_acc_eqn1, imag_acc_eqn1);
%acceleration eqn for Al3 and Al4.
ddL_eqn2 = diff(dL_eqn2,Th2)*Om2 +diff(dL_eqn2,Om2)*Al2 + diff(dL_eqn2,Th3)*Om3 +diff(dL_eqn2,Om3)*Al3 + diff(dL_eqn2,Th4)*Om4 +diff(dL_eqn2,Om4)*Al4 ;
real_acc_eqn2 = real(ddL_eqn2);
imag_acc_eqn2 = imag(ddL_eqn2);
[Al3, Al4]=solve (real_acc_eqn2, imag_acc_eqn2);
  3 comentarios
Aamna Alshehhi
Aamna Alshehhi el 3 de Nov. de 2019
I wanna take 101 roots of quadratic equations.
Walter Roberson
Walter Roberson el 3 de Nov. de 2019
roots() can only handle a vector of values representing the polynomial coefficients. It cannot be used to calculate the roots for all 101 equations at the same time.
What you can do is just use the formula for roots of a quadratic,
(-b +/- sqrt(b.^2 - 4.*a.*c))./(2*a)

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Quadratic Programming and Cone Programming 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