Effacer les filtres
Effacer les filtres

Save outputs of a function to a vector for different inputs

1 vue (au cours des 30 derniers jours)
cruxsign
cruxsign le 11 Août 2015
Commenté : Star Strider le 11 Août 2015
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

Réponse acceptée

Star Strider
Star Strider le 11 Août 2015
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;
  2 commentaires
cruxsign
cruxsign le 11 Août 2015
Thank you so much, it worked.
Star Strider
Star Strider le 11 Août 2015
My pleasure.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB 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!

Translated by