multiply with a vector inside for loop

12 ビュー (過去 30 日間)
Olga Rakvag
Olga Rakvag 2022 年 3 月 13 日
編集済み: Olga Rakvag 2022 年 3 月 13 日
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

採用された回答

Torsten
Torsten 2022 年 3 月 13 日
編集済み: Torsten 2022 年 3 月 13 日
% 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 件のコメント
Olga Rakvag
Olga Rakvag 2022 年 3 月 13 日
編集済み: Olga Rakvag 2022 年 3 月 13 日
Thanks a lot! It was funny, that I didn't need a for loop :-) I added also
T1=transpose(T)% at the end so now it looks like excel exactly

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by