how can i use for loop for this script
3 次查看(过去 30 天)
显示 更早的评论
for b=1:1:1200
omega(b)=b;
Omega(b)=omega(b)*2*pi;
alpa=-(roh*omega(b)^2/E)-(roh*omega(b)/k*G);
beta=-(roh*A*omega(b)^2/E*I)-(roh^2*omega(b)^4/E*k*G);
for j=1:4
k_j(b) =(-1)^(j(b)/2)*([sqrt(alpa+(-1)^j(b))*sqrt((alpa)^2+4*beta)/2]);
k1(b)=k_j(b);
k2(b)=k_j(b);
k3(b)=k_j(b);
k4(b)=k_j(b);
5 个评论
DGM
2021-5-6
编辑:DGM
2021-5-6
I see that there are loops. I asked what j(b) is supposed to be. The variable j is a scalar within the scope of the inner loop. You are trying to find j(1:1200). There is no j(2), let alone j(1200). I don't understand what you're trying to do with this expression.
Also: is Omega different than omega, or is that a typo?
This doesn't appear to need any loops. Just use two orthogonal vectors, and your results will be 1200x4
b = (1:1200).';
roh = 0.1;
A = 1;
E = 1;
k = 1;
G = 1;
I = 1;
omega = 2*pi*b; % i'll assume that Omega is a typo
alpa = -(roh*omega.^2/E)-(roh*omega/k*G);
beta = -(roh*A*omega.^2/E*I)-(roh^2*omega.^4/E*k*G);
j=1:4;
% this whole expression makes no sense
%k_j =(-1)^(j(b)/2)*([sqrt(alpa+(-1)^j(b))*sqrt((alpa)^2+4*beta)/2]);
% if we assume j(b) can be replaced with j
k_j = (-1).^(j/2) .* sqrt(alpa + (-1).^j) .* sqrt(alpa.^2 + 4*beta)/2;
% i guess these are just placeholders?
k1=k_j;
k2=k_j;
k3=k_j;
k4=k_j;
采纳的回答
Sambit Supriya Dash
2021-5-6
As per your given expression in the question,
the assumptions of the constants here taken as 1,
The running code is,
roh = 1; A = 1; E = 1; I = 1; k = 1; G = 1;
for b = 1:1200
omega(b) = b;
Omega(b) = omega(b)*2*pi;
alpa(b) = -(roh*omega(b)^2/E)-(roh*omega(b)/k*G);
beta(b) = -(roh*A*omega(b)^2/E*I)-(roh^2*omega(b)^4/E*k*G);
for j = 1:4
k_j =(-1)^(j/2)*((sqrt(alpa(b)+(-1)^j)*sqrt((alpa(b))^2+4*beta(b))/2));
k1(b)=k_j;
k2(b)=k_j;
k3(b)=k_j;
k4(b)=k_j;
end
end
And the symbolic solution would be,
syms roh A E I k G
for b = 1:1200
omega(b) = b;
Omega(b) = omega(b)*2*pi;
alpa(b) = -(roh*omega(b)^2/E)-(roh*omega(b)/k*G);
beta(b) = -(roh*A*omega(b)^2/E*I)-(roh^2*omega(b)^4/E*k*G);
for j = 1:4
k_j =(-1)^(j/2)*((sqrt(alpa(b)+(-1)^j)*sqrt((alpa(b))^2+4*beta(b))/2));
k1(b)=k_j;
k2(b)=k_j;
k3(b)=k_j;
k4(b)=k_j;
end
end
Hope this helps....
0 个评论
更多回答(2 个)
Sambit Supriya Dash
2021-5-6
k_j(b) =(-1)^(j(b)/2)*([sqrt(alpa+(-1)^j(b))*sqrt((alpa)^2+4*beta)/2]);
Provide the original formula in a text or written manner (not the typed one). Then, I will guide you further.
Sambit Supriya Dash
2021-5-6
According to your given document,
As per this formula,
Your parameters in the code should be,
alpha(b) = -((rho*w^2)/E)-((rho*w^2)/(k*G));
beta(b) = -((rho*A*w^2)/(E*I))-(((rho^2)*w^4)/(E*k*G));
k_j(b) = (-1^(j*0.5))*sqrt(((alpha(b)+((-1^j)*(sqrt(((alpha(b))^2)+(4*beta(b)))))))*0.5);
For Symbolic Calculations,
syms rho A E I k G
for b=1:1200
omega = b;
w = omega*2*pi;
alpha = -((rho*w^2)/E)-((rho*w^2)/(k*G));
beta = -((rho*A*w^2)/(E*I))-(((rho^2)*w^4)/(E*k*G));
for j=1:4
k_j(b) = (-1^(j*0.5))*sqrt(((alpha+...
((-1^j)*(sqrt(((alpha)^2)+(4*beta))))))*0.5);
end
k1=k_j;
k2=k_j;
k3=k_j;
k4=k_j;
end
For specific values of the parameters,
rho = 1; A = 1; E = 1; I = 1; k = 1; G = 1;
for b=1:1200
omega = b;
w = omega*2*pi;
alpha = -((rho*w^2)/E)-((rho*w^2)/(k*G));
beta = -((rho*A*w^2)/(E*I))-(((rho^2)*w^4)/(E*k*G));
for j=1:4
k_j(b) = (-1^(j*0.5))*sqrt(((alpha+...
((-1^j)*(sqrt(((alpha)^2)+(4*beta))))))*0.5);
end
k1=k_j;
k2=k_j;
k3=k_j;
k4=k_j;
end
Hope this works good.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!