Defining Variables

1 vue (au cours des 30 derniers jours)
Alex
Alex le 8 Fév 2012
Modifié(e) : Cedric le 5 Oct 2013
Hi, I'm a fairly new user of Matlab, and I set up a list of variable definitions like so:
n0=1;
n21=1.694;
n22=1.7046;
n23=1.7152;
k21=3.666;
k22=3.7066;
k23=3.7274;
y1=250;
y2=251;
y3=252;
z=(n-1i.*k);
w1=(n21-1i.*k21);
w2=(n22-1i.*k22);
w3=(n23-1i.*k23);
a1=((n0-z)./(n0+z));
a2=((n0-z)./(n0+z));
a3=((n0-z)./(n0+z));
b1=((z-w1)./(z+w1));
b2=((z-w2)./(z+w2));
b3=((z-w3)./(z+w3));
c1=((4.*pi)./y1);
c2=((4.*pi)./y2);
c3=((4.*pi)./y3);
R1=.922269;
R2=.92401;
R3=.925751;
This list is used to define variables for these 3 equations to be solved simultaneously:
fcns(1)=R1+(b1.*exp(c1.*1i.*d.*z).*((R1.*a1)-1))-a1;
fcns(2)=R2+(b2.*exp(c2.*1i.*d.*z).*((R2.*a2)-1))-a2;
fcns(3)=R3+(b3.*exp(c3.*1i.*d.*z).*((R3.*a3)-1))-a3;
When I run the .m file, however, I get an error at z=(n-1i.*k) saying that n is an 'undefined variabe'. n is supposed to be undefined, as I solve for it later. How can I resolve this? Also, is there a way to put Matlab code into these entries to help organize them?

Réponse acceptée

Sean de Wolski
Sean de Wolski le 8 Fév 2012
Do you have the symbolic toolbox? If you do, define n as a symbolic variable
syms n
and then you can do exactly what you were talking about. Else defined it as an input to an anonymous function that you could later solve with fsolve (Optimization toolbox).
doc fsolve
and
web([docroot '/techdoc/ref/function_handle.html'])
  1 commentaire
Alex
Alex le 8 Fév 2012
Ahh, thanks a lot! I do have the Symbolic Toolbox, how helpful!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by