cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

variable is undefined

ptc-4284952
1-Newbie

variable is undefined

Hi everyone,

I have a problem with the variable being undefined. In the Mathcad 14 file I attached, at the end of the codes, they say my 'base' and 'lambda' is undefined but I clearly defined it before. Below are the screenshots.

undif1.png

undiff2.png

Thanks for any help in advace!

15 REPLIES 15

I think by the definition the funktion f must be not C1(...) but C1*(...).

And see the F6 function in attach.

Hi Valery,

Did you change the F6 function? Doesn't fix the problem though. I am using Mathcad 14.

It's difficult to tell without the Mathcad file, could you attach the file?

In the function, base is in the argument list, so doesn't matter if defined before as far as that equation goes.

Looks like the Minimize failed, and that's why Lambda, and the rest of the variables as well, are no longer defined?

Did you provide in a solve block and provide guess values?

Hi again Wayne,

yea. The Mathcad file is attached at the bottom of the original post. I put it in .rar format. I attached it in the post again. It is "fitting.rar"

How did you know the Minimize failed?

I thought the values I defined earlier are the guess values?

Thanks!

RichardJ
19-Tanzanite
(To:ptc-4284952)

When you evaluate the function F6 for the given parameters, it's complex. This causes Minimize to fail, with a completely misleading error message.

You should always plot the data and the estimated function before performing the fit. That way you have some idea of how close you are.

Minimize is not really the best way to fit the data, but we can come back to that when you have fixed the function F6 and/or the estimated parameters so that the estimated function is at least reasonably close to the data.

Hi Richard,

The data I put on there is just a portion of the data. I have about 2700 data points so I just used the first few.

What you said is exactly what the program is supposed to do. All the F1,F2,F3,etc are part of the estimating function. The final formula is a combination of a Lorentzian and Pake doublet, which is supposed to be F6.

I am actually reproducing the formula from a .pdf research paper file and the parameters are as stated in the .pdf file and it is a reasonable guess for the data.

The program is supposed to minimize the parameters in the SSR function, which is a chi^2 function. Once I obtain the minimized values, I will apply them to the TotalAreaFit and PowderPartArea to obtain values, which is what I want.

Thanks.

Ian

RichardJ
19-Tanzanite
(To:ptc-4284952)

What you said is exactly what the program is supposed to do. All the F1,F2,F3,etc are part of the estimating function. The final formula is a combination of a Lorentzian and Pake doublet, which is supposed to be F6.

Maybe that's what it is supposed to be, but it's not, because it's complex. The reason it's complex is that F1 is complex (unlike F2, which is unused, but gives real values).

Is the first column of the data matrix supposed to be the frequency?

Hey Richard!

Hmm. F2 is used. It is part of F3.

And yes, the first column is frequency.

I am not sure how F1 gets complex. But I think the issue could lie with how I defined 'f'. I attached some screenshots of it below. Did I enter it correctly?

Thanks!

part_1.png

part_2.png

Hi Wayne,

Huh. Why are there zeroes at the end of my SSR? And there is a F6(...) = (8) there too. I don't know how it got there. It doesn't show in my original window. Starting to think if my Mathcad has issues.

I am trying to minimize the parameters, not to solve for them. That's why I used Minimize and not Find. I am trying to minimize the parameters in SSR, which is a chi^2 function. Then apply those values to TotalAreaFit and PowderPartArea. Minimize doesn't work?

Ian

PS: Was your post deleted or something? I tried to reply to it but it disappeared. Did you delete it?

Ian, yes I deleted my post because right after I posted, I realized the Find() was of no value. I started to look at the behavior of the SSR function with respect to each variable to see if there were any problems, I did not finish, but did find the SSR has a jump at Beta as it approaches 0. So perhaps you need to but some limits on some of the variables.

Hi Wayne!

Hmm. I was thinking it could be how I entered my 'f' function early on in the program. I attached some screenshots on where I think could have entered the function incorrectly. Could you double check if this is the case? This is the same case as my 'multiple if' post earlier.

Thanks!

part_1.png

part_2.png

Attached some cursor observations. There is a problem with f, the ranges overlap, I think you need f1 for F1 and f2 for F2 and f4 for F4 because of the ranges of the integrals?

Possibly change to a solve block and add variable constraints. As A.non indiated, he may have some better methods for that.

Sorry for the late reply. Was busy the past couple of days.

Hmm...having multiple 'f' sounds like an idea, since then I can elimnate the problem of syntax not working properly.

Solve block...but isn't that only used to solve for variables? Mine is minimizing them.

Use minerr() in a solve block, ie minerr() of f() should result in getting the value as close to 0 as possible, so minimizing. Or, getting f()=A as close as possible, given the constraints, which can be llimits on the variables, ratios, or other functions that must also be satisified.

hmm. ok. i can try that.

but i was just looking at my function. it manages to evaluate SSR to be a real number at the end and it is the same SSR i am using in my minimize function. Therefore, does it matter if my function f was evaluating imaginery numbers in between? it should not affect my minimize function, right?

Announcements