필터 지우기
필터 지우기

Save outputs of a function to a vector for different inputs

조회 수: 1 (최근 30일)
cruxsign
cruxsign 2015년 8월 11일
댓글: Star Strider 2015년 8월 11일
Dear all I have a function with some constant outputs and one variable input. For example, for 4 different angles(i1) I need to save the output Rpp for each angle and place it in a vector with a size of (1,4). Please help me with this question. I got stuck and cannot go further. Thanks in advance I have the following codes;
function [ Rpp ] = sszoeppritz( Vp1,Vs1,rho1,Vp2,Vs2,rho2,i1 )
Vp1=3300;
Vp2=3850;
rho1=2390;
rho2=2510;
Vs1=1500;
Vs2=2000;
i1=[10 15 35 40]
p=sin(i1)/Vp1;
i2=asin(p*Vp2);
j1=asin(p*Vs1);
j2=asin(p*Vs2);
a=rho2*(1-2*Vs2^2*p.^2)-rho1*(1-2*Vs1^2*p^2);
b=rho2*(1-2*Vs2^2*p.^2)+2*rho1*Vs1^2*p^2;
c=rho1*(1-2*Vs1^2*p.^2)+2*rho2*Vs2^2*p^2;
d=2*(rho2*Vs2^2-rho1*Vs1^2);
E=b*cos(i1)/Vp1+c*cos(i2)/Vp2;
F=b*cos(j1)/Vs1+c*cos(j2)/Vs2;
G=a-d*(cos(i1)/Vp1)*(cos(j2)/Vs2);
H=a-d*(cos(i2)/Vp2)*(cos(j1)/Vs1);
D=E*F+G*H*p^2;
Rpp=((b*(cos(i1)/Vp1)-c*cos((i2)/Vp2))*F-(a+d*((cos(i1)/Vp1))*(cos(j2)/Vs2))*H*p^2)/D;
end

채택된 답변

Star Strider
Star Strider 2015년 8월 11일
You need to vectorise everything and your code runs:
Vp1=3300;
Vp2=3850;
rho1=2390;
rho2=2510;
Vs1=1500;
Vs2=2000;
i1=[10 15 35 40];
p=sin(i1)/Vp1;
i2=asin(p*Vp2);
j1=asin(p*Vs1);
j2=asin(p*Vs2);
a=rho2*(1-2*Vs2^2*p.^2)-rho1*(1-2*Vs1.^2*p.^2);
b=rho2*(1-2*Vs2^2*p.^2)+2*rho1*Vs1^2*p.^2;
c=rho1*(1-2*Vs1^2*p.^2)+2*rho2*Vs2^2*p.^2;
d=2*(rho2*Vs2^2-rho1*Vs1^2);
E=b.*cos(i1)./Vp1+c.*cos(i2)/Vp2;
F=b.*cos(j1)./Vs1+c.*cos(j2)/Vs2;
G=a-d*(cos(i1)/Vp1).*(cos(j2)/Vs2);
H=a-d*(cos(i2)/Vp2).*(cos(j1)/Vs1);
D=E.*F+G.*H.*p.^2;
Rpp=((b.*(cos(i1)/Vp1)-c.*cos((i2)/Vp2)).*F-(a+d*((cos(i1)/Vp1)).*(cos(j2)/Vs2)).*H.*p.^2)./D;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by