필터 지우기
필터 지우기

Defining Variables

조회 수: 3 (최근 30일)
Alex
Alex 2012년 2월 8일
편집: Cedric 2013년 10월 5일
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?

채택된 답변

Sean de Wolski
Sean de Wolski 2012년 2월 8일
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
Alex
Alex 2012년 2월 8일
Ahh, thanks a lot! I do have the Symbolic Toolbox, how helpful!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by