Zeroes on an equations with a variable of a specific range

1 回表示 (過去 30 日間)
Fuad Alami
Fuad Alami 2016 年 11 月 13 日
回答済み: Yeshwanth Devara 2016 年 11 月 16 日
I'm trying to find zeroes for a specific function but I keep on getting this error message:
"Error using fzero (line 428)
Second argument must be a scalar or vector of length 2.
Error in Problem3b (line 14)
x=fzero(fun,E)"
My current set up looks as such:
m=9.11*10^-31;
hbar=1.055*10^-34;
e=1.602*10^-19;
Vo=(1.42-0.354)*e;
L1=(4*10^-9);
L2=(10*10^-9);
m1=0.067;
m2=0.025;
meff=((2*m1*m*L1)+(m2*m*L2))/(2*L1+L2);
range=linspace(0,Vo,10^6);
E=linspace(0,Vo,200);
k=(sqrt(2.*meff.*E))./hbar;
B=(sqrt(2.*meff.*(Vo-E)))./hbar;
fun=@(E) ((sqrt(2.*E.*(Vo-E)))/(2.*E-Vo))-(tan(k.*L2).*tan(h.*B.*L1));
x=fzero(fun,E)
  2 件のコメント
Jan
Jan 2016 年 11 月 13 日
The error message is clear. Read the documentation of fzero and explain, why you provide a 1x200 vector instead of the required value. Guessing your intention is not efficient.
Fuad Alami
Fuad Alami 2016 年 11 月 13 日
Yeah, I don't really code so I have no idea where to start with what. Got throwen into a 4th year phys-eng class with no prior matlab experience....

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

回答 (1 件)

Yeshwanth Devara
Yeshwanth Devara 2016 年 11 月 16 日
As Jan suggested, the second argument expects a real scalar or a 2-element real vector. It appears the second argument in your case is a 1x200 vector. Refer to the documentation for more information on fzero function and its input arguments.

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by