multiply with a vector inside for loop
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to simply multiply with a vector for every iteration of a_xn inside for loop, and then multiply the result of each iteration of a_xn*SF with another vector n=[6 5 4 3 2 1 0] But I could not figure out how to make it? I got the right answers for everything within a_xn. See picture

Shold get following answers (made it in Excel)

clc
clear
T_az=16;
zeta_a=15;
lambda =1.57*T_az^2
wt=0.;
k=2*pi/lambda;
omega=2*pi/T_az
rho=1.025;
h=160;
H=2*zeta_a;
CM=2;
D=10;
% vinkel i grader
alfa = 60;
beta=73.9;
%tabelverdier
% finding slope with to equations with 2 unknowns
syms a b
eqns = [ -160*a+b==-37.5, -30*a+b== 0];
vars = [a b];
[sola, solb] = solve(eqns,vars)
% finding a_x, a_z, x_z, a_xn, display after each iteration, after each
% loop, like excel :-)
T = [];
i=0;
j=0;
n=[6 5 4 3 2 1 0];
for z=[-40 -60 -80 -100 -120 -140 -160]
x_z=15/52*z+225/26;
a_x = omega^2*zeta_a*exp(k*z)*sin(k*x_z+pi/2);
a_z =- omega^2*zeta_a*exp(k*z)*cos(k*x_z+pi/2);
a_xn=a_x*sind(beta)-a_z*cosd(beta);
for SF=[1 4 2 4 2 4 1]
y(SF)=a_xn*SF;
p_n=y*n
j=j+1;
end
i=i+1;
T = [T; z,x_z, a_x,a_z,a_xn,y];
end
T
0 commentaires
Réponse acceptée
Torsten
le 13 Mar 2022
Modifié(e) : Torsten
le 13 Mar 2022
% finding a_x, a_z, x_z, a_xn, display after each iteration, after each
% loop, like excel :-)
n = [6 5 4 3 2 1 0];
SF = [1 4 2 4 2 4 1];
z = [-40 -60 -80 -100 -120 -140 -160];
x_z = 15/52*z+225/26;
a_x = omega^2*zeta_a*exp(k*z).*sin(k*x_z+pi/2);
a_z =- omega^2*zeta_a*exp(k*z).*cos(k*x_z+pi/2);
a_xn = a_x*sind(beta)-a_z*cosd(beta);
y = a_xn.*SF;
p_n = y.*n;
T = [z;x_z;a_x;a_z;a_xn;y;p_n].'
1 commentaire
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
