Implicit function nonlinear curve fitting error-debugging mode
4 ビュー (過去 30 日間)
古いコメントを表示
function diff=fit_pd(x,X,Y)
global X Y;
diff=(-6432)*(1-Y./1040)-1.987*Y.*log(X)-x(1)*(1-X).^2*(1-Y./x(2));
x0=[-1000,10000]';
x=lsqnonlin(@fit_pd,x0,[],[],xdata,ydata)
%xdata,ydata get from experimental value
Why debug mode? command return , it says that input argument is undefined. I use global X Y in the function definition. It does not work.
Thanks so much for answers.
0 件のコメント
回答 (3 件)
Fangjun Jiang
2011 年 11 月 6 日
I saw a few problems.
- Use of x (low case) and X (up case) as two variables is not a good idea.
- diff is a MATLAB function. Try not to use it as a variable name.
- Inside the definition of your function fit_pd(), you are using @fit_pd. Is this going to cause a chicken-and-egg problem?
2 件のコメント
Fangjun Jiang
2011 年 11 月 6 日
All right, then Walter's link regarding passing extra parameters should be all you need. Using global variables works too. You just need to also declare global in MATLAB base workspace.
Walter Roberson
2011 年 11 月 6 日
1) Do not use the same name for a parameter and a global variable.
2) Your command
global X Y;
is the equivalent of
global('X', 'Y;')
which would attempt to declare a variable named "X" and another variable named "Y;" (Y-semicolon).
When you use command mode such as
global X Y
or
cd C:\System32\Documents And Settings\Liang\
then do not put semi-colons on the end of them, or else the semi-colon will be treated as input to the command.
3) If you are trying to execute your function fit_pd by pressing F5 or selecting Run from the menu, then it is going to be called with no arguments. You might have (perhaps) given meaning to X and Y through your global statement, but your x (lower-case) would still be undefined.
4) If we are to understand that the three lines from x0= onwards are part of a different file, and you are running that second file to invoke lsqnonlin on the function fit_pd, then if you examine the documentation for lsqnonlin, you will see that the function you designate will be called with exactly one argument. If you want to pass additional arguments then see the documentation that is referred to in the lsqnonlin reference page, Passing Extra Parameters
5) If we are to understand that the three lines from x0= onwards are part of a different file, and you are running that second file to invoke lsqnonlin on the function fit_pd, then notice that you did not define or give initial values to the global variables X and Y. In such a situation, MATLAB would initialize the variables to the empty array.
6 件のコメント
Walter Roberson
2011 年 11 月 6 日
It means that if you want more than one argument you need to follow the instructions in the link above "Passing Extra Parameters"
参考
カテゴリ
Help Center および File Exchange で Entering Commands についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!