Stack Overflow Asked on November 15, 2021
I’m trying to graph a function for different values of Chi and Wn. Here’s the function.
A1=0.1
A2=0.2
A3=0.3 //Valores de chi
A4=0.4
A5=0.5
B1=29
B2=30
B3=65 //valores deW
B4=80
B5=100
C=1
u=linspace(0,600)
t=linspace(0,30)
r=((sqrt(1-A1^2))*B1)
r1=((sqrt(1-A2^2))*B2)
r2=((sqrt(1-A3^2))*B3)
r3=((sqrt(1-A4^2))*B4)
r4=((sqrt(1-A5^2))*B5)
x=(%e^(t-A1*B1))( C*cos(r)*B1*t)' + ((C+(A1*B1*C))/((r)*B1)) *(sin(r)*B1*t)
x1=(%e^(t-A2*B2))( C*cos(r1)*B2*t)' + ((C+(A2*B2*C))/((r1)*B2)) *(sin(r1)*B2*t)
x2=(%e^(t-A3*B3))( C*cos(r2)*B3*t)' + ((C+(A3*B3*C))/((r2)*B3)) *(sin(r2)*B3*t)
x3=(%e^(t-A4*B4))( C*cos(r3)*B4*t)' + ((C+(A4*B4*C))/((r3)*B4)) *(sin(r3)*B4*t)
x4=(%e^(t-A5*B5))*( C*cos(r4)*B5*t)' + ((C+(A5*B5*C))/((r4)*B5)) *(sin(r4)*B5*t)
xlabel("t")
ylabel("x(t)")
title("Grafica de la Ecuación")
plot(t,x,t,x1,t,x2,t,x3,t,x4)
I get Invalid error in line 19
You use too many useless parenthesis (sometimes forget needed ones), use dumb variable names (use the names of variables in the formula) and do not use use dot-prefixed operators. Here is a readable working code to do what you want:
clear
//Valores de zeta
zeta = 0.1:0.1:0.5
//valores de omega
omega = [29 30 65 80 100]
x_0 = 1;
xdot_0 = 1;
t = linspace(0,3,1000)
for i=1:length(zeta)
r = sqrt(1-zeta(i)^2)*omega(i);
x(i,:) = exp(-zeta(i)*omega(i)*t).*(x_0*cos(r*t) + (xdot_0+zeta(i)*omega(i)*x_0)/r*sin(r*t))
end
clf
plot(t,x)
xlabel("t")
ylabel("x(t)")
title("Grafica de la Ecuación")
xstring(0.2,0.5,"$large x(t)=exp(-zetaomega_n t)left{ x_0cosleft(sqrt{1-zeta^2}omega_n tright)+frac{dot x_0+zetaomega_n x_0}{sqrt{1-zeta^2}omega_n} sinleft(sqrt{1-zeta^2}omega_n tright)right}$")
Answered by Stéphane Mottelet on November 15, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP