Problem with fzero

2 ビュー (過去 30 日間)
Mehul Makwana 2011 年 11 月 3 日
MAIN FUNCTION
function evaluation=dispersion_separable2(lambda2,m10,M1,M2)
global lambda Mass1 Mass2
Mass1=M1;
Mass2=M2;
m10;
lambda=sqrt(lambda2);
evaluation=1-lambda^2*(2*M1-m10)*the_integral;
SECOND FUNCTION
function relation=integrand_separable2(alpha,beta);
global lambda Mass1 Mass2 m10
M1=Mass1;
M2=Mass2;
relation=(-cos(beta) * M1 * lambda ^ 2 - cos(beta) * M2 * lambda ^ 2 + 0.4e1 * cos(beta) - cos(alpha) * M1 * lambda ^ 2 - cos(alpha) * M2 * lambda ^ 2 + 0.4e1 * cos(alpha) - 0.24e2 + 0.14e2 * M1 * lambda ^ 2 + 0.30e2 * M2 * lambda ^ 2 - 0.2e1 * M1 ^ 2 * lambda ^ 4 - 0.10e2 * M2 ^ 2 * lambda ^ 4 + M2 ^ 3 * lambda ^ 6 - 0.12e2 * M1 * lambda ^ 4 * M2 + M2 * lambda ^ 6 * M1 ^ 2 + 0.2e1 * M2 ^ 2 * lambda ^ 6 * M1) / (0.66e2 - 0.96e2 * M1 * lambda ^ 2 - 0.96e2 * M2 * lambda ^ 2 + 0.36e2 * M1 ^ 2 * lambda ^ 4 + 0.36e2 * M2 ^ 2 * lambda ^ 4 - 0.4e1 * M2 ^ 3 * lambda ^ 6 + 0.104e3 * M1 * lambda ^ 4 * M2 - 0.28e2 * M2 * lambda ^ 6 * M1 ^ 2 - 0.28e2 * M2 ^ 2 * lambda ^ 6 * M1 + 0.2e1 * M1 * lambda ^ 8 * M2 ^ 3 + 0.2e1 * M1 ^ 3 * lambda ^ 8 * M2 + 0.4e1 * M1 ^ 2 * lambda ^ 8 * M2 ^ 2 - 0.4e1 * M1 ^ 3 * lambda ^ 6 - 0.32e2 * cos(alpha) - 0.4e1 * cos(beta) * M1 * lambda ^ 4 * M2 - 0.4e1 * cos(alpha) * M1 * lambda ^ 4 * M2 - 0.32e2 * cos(beta) - 0.2e1 * cos(alpha - beta) - 0.2e1 * cos(alpha + beta) + cos(0.2e1 * alpha) + cos(0.2e1 * beta) + 0.16e2 * cos(beta) * M2 * lambda ^ 2 + 0.16e2 * cos(alpha) * M1 * lambda ^ 2 + 0.16e2 * cos(beta) * M1 * lambda ^ 2 - 0.2e1 * cos(beta) * M1 ^ 2 * lambda ^ 4 - 0.2e1 * cos(beta) * M2 ^ 2 * lambda ^ 4 + 0.16e2 * cos(alpha) * M2 * lambda ^ 2 - 0.2e1 * cos(alpha) * M2 ^ 2 * lambda ^ 4 - 0.2e1 * cos(alpha) * M1 ^ 2 * lambda ^ 4);
AND I GET THE ERROR :
Error using ==> fzero at 316
FZERO cannot continue because user supplied function_handle ==> @(lambda2)dispersion_separable2(lambda2,1.2,1,1)
failed with the error below.
Index exceeds matrix dimensions.
I BELIEVE THE ISSUE IS WITH THE LONG EXPRESSION, ALTHOUGH I'M NOT SURE HOW THIS COULD RELATE TO THE ERROR SHOWN ABOVE ?!
ANY HELP WOULD BE VERY MUCH APPRECIATED. :)

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

回答 (2 件)

Ora Zyto 2011 年 11 月 7 日
Using global variables is a very bad idea. It seems like you're working exclusively with scalars, including M1 / M2 / Mass1 / Mass2. FZERO expects the function to return a scalar. Are all your variables indeed scalars? Could the values of the global variables have changed and they are now vectors / matrices?
Consider not using global variables. The error comes from a dimension mismatch. It would be helpful to include your actual call to FZERO.
Ora
0 件のコメント表示非表示 -1 件の古いコメント

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

Walter Roberson 2011 年 11 月 7 日
The only possibility I am coming up with is that you redefined sin() or cos() as functions, or that integrand_separable2 is defined within a nested scope that defines sin() or cos() as variables.
I suggest that at the command line, you invoke
dbstop if error
dbstop if caught error
and then run again; when it stops, examines everything carefully.

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

Community Treasure Hunt

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

Start Hunting!

Translated by