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일

1 개 추천

% 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개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2022년 3월 13일

편집:

2022년 3월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by