フィルターのクリア

how to generate a function using symbolic expression and plot that

3 ビュー (過去 30 日間)
Nafisa Amin
Nafisa Amin 2019 年 7 月 16 日
回答済み: Walter Roberson 2019 年 7 月 16 日
I'm trying to calculate the root,gamma of my function over a range of angles from 0 to 90 but it's giving om errors which I don't know how to fix. here is my code and the error message,
function [g1] = rtfnd(n_1,nu_bar_0_cm,thetad)
im = sqrt(-1);
c = 2.99792458e+08;
mu_0=4*pi*1e-7;
eps_0 = 8.8541878176e-12;
phid = 0;
nu_bar_0 = nu_bar_0_cm * 1e2;
lambda_0 = 1/nu_bar_0;
eps_1 = ((n_1)^2)*eps_0*eye(3);
nu = c/lambda_0;
lambda_1 = lambda_0/n_1;
w=2*pi*nu;
Al = 2*pi*sind(thetad)*cosd(phid)/lambda_1;%alpha
Bt= 2*pi* sind(thetad) * sind(phid)/lambda_1; % beta
syms gamma
x11 = (w^2)*mu_0*eps_1(1,1)-(Bt^2)-(gamma^2);
x12 = (w^2)*mu_0*eps_1(1,2)+Al*Bt;
x13 = (w^2)*mu_0*eps_1(1,3)+Al*gamma;
x21 = (w^2)*mu_0*eps_1(2,1)+Al*Bt;
x22 = (w^2)*mu_0*eps_1(2,2)-(Al^2)-(gamma^2);
x23 = (w^2)*mu_0*eps_1(2,3)+Bt*gamma;
x31 = (w^2)*mu_0*eps_1(3,1)+Al*gamma;
x32 = (w^2)*mu_0*eps_1(3,2)+Bt*gamma;
x33 = (w^2)*mu_0*eps_1(3,3)-(Bt^2)-(Al^2);
M = [x11 x12 x13; x21 x22 x23; x31 x32 x33];
detM = det(M);
gamma = solve(detM,gamma);
g1 = double(gamma);
%%%%%%%%%%%%%%%%%%%%% i called this file testroot_2.m in the workspace
n_1 = 1 ;
nu_bar_0_cm=1000;
theta_points = 361;
theta_start = 0;
theta_end = 90;
theta_incr = (theta_end - theta_start)/(theta_points - 1);
theta = theta_start:theta_incr:theta_end;
for ii = 1:length(theta)
A = rtfnd(n_1,nu_bar_0_cm,thetad);
end
%%%%%%%%%%%%% this is the error message
>> testroot_2
Error: File: rtfnd.m Line: 49 Column: 1
"gamma" previously appeared to be used as a function or command,
conflicting with its use here as the name of a variable.
A possible cause of this error is that you forgot to initialize
the variable, or you have initialized it implicitly using load
or eval.
Error in testroot_2 (line 15)
A = rtfnd(n_1,nu_bar_0_cm,thetad);

採用された回答

Walter Roberson
Walter Roberson 2019 年 7 月 16 日
Replace
syms gamma
With
gamma = sym('gamma');

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by