substituting multiple values in symbolic formula?

2 ビュー (過去 30 日間)
Sharif Khalil
Sharif Khalil 2018 年 6 月 29 日
編集済み: Walter Roberson 2018 年 6 月 30 日
I have this symbolic formula that is a variable of theta and phi, and I want to substitute the theta and phi with the following values in the following formula:
if true
% code
end
theta = -pi/2:pi/180:pi/2;
phi = -pi:pi/180:pi;
U = abs(sin(pi*cos(phi)*sin(theta))*sin(pi*sin(phi)*sin(theta)))^2/(abs(sin((pi*cos(phi)*sin(theta))/2))^2*abs(sin((pi*sin(phi)*sin(theta))/2))^2);
  2 件のコメント
Ameer Hamza
Ameer Hamza 2018 年 6 月 30 日
theta and phi have different lengths. For substitution, they must have equal lengths.
Sharif Khalil
Sharif Khalil 2018 年 6 月 30 日
if they have equal length, how to do the substitution?

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

採用された回答

Walter Roberson
Walter Roberson 2018 年 6 月 30 日
First create the symbolic formula. Next create your vectors of values but give them a different name than the variables in the formula. Then use ndgrid to create a grid of values for the two variables and use different variable names still. Finally,
Output = subs(U, {theta, phi}, {thetaGrid, phiGrid}) ;
There is another possibility that does not require creating the grid but it involves two subs calls and being careful about row and column vectors.
  5 件のコメント
Walter Roberson
Walter Roberson 2018 年 6 月 30 日
編集済み: Walter Roberson 2018 年 6 月 30 日
1) First create the symbolic formula.
syms theta phi real
Psi_x = k*dx*sin(theta)*cos(phi) + Beta_x;
Psi_y = k*dy*sin(theta)*sin(phi) + Beta_y;
AF_Field = (sin(Nx*Psi_x/2)/(sin(Psi_x/2)))*...
(sin(Ny*Psi_y/2)/(sin(Psi_y/2)));
U = abs((fi*AF_Field)).^2;
2) Next create your vectors of values but give them a different name than the variables in the formula.
Theta = -pi/2:pi/180:pi/2; % Elevation Angle (radian)
Phi = -pi:pi/180:pi; % Azimuth Angle (radian)
3) Then use ndgrid to create a grid of values for the two variables and use different variable names still.
[thetaGrid, phiGrid] = ndgrid(Theta, Phi);
4) Finally,
Output = subs(U, {theta, phi}, {thetaGrid, phiGrid}) ;
Sharif Khalil
Sharif Khalil 2018 年 6 月 30 日
Thank you

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAssumptions についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by