Physics Forums (http://www.physicsforums.com/index.php)
-   Math & Science Software (http://www.physicsforums.com/forumdisplay.php?f=189)

 aminbkh Apr19-11 12:43 AM

Hi,
I have a question about fitting in Mathematica.I have a function like this:
F=T*Y^(0.5) T is temperature but Y obtained from this coupled equation 1-u*Y=u(1-u/Y^.4)^.5*Y
I have T and F from experimental data.so I want to obtain u from fitting.
could you please advise me how can I do it by Mathematica.
Thank you

 DaleSpam Apr19-11 03:34 PM

You don't need to fit this. You can solve for u in terms of T and F eliminating Y.

Try something like:
Solve[equation1, u] /. Solve[equation2, Y]

This will solve the second equation for Y and substitute that into the solution for u.

 aminbkh Apr19-11 06:56 PM

Quote:
 Quote by DaleSpam (Post 3255585) You don't need to fit this. You can solve for u in terms of T and F eliminating Y. Try something like: Solve[equation1, u] /. Solve[equation2, Y] This will solve the second equation for Y and substitute that into the solution for u.
Thanks ,actually you cant do that because as I told you this a coupled equation,I apology because in formula I forgot something the second formula is something like this
1-u*Y=u(1-u/Y^.4)^.5*Y^.45 and then I should put this in this equation F=T*Y^(0.5).
now could you please me tell what to do.I appreciate it.

 rynlee Apr19-11 07:35 PM

personally I prefer matlab or excel for numerical solutions over mathematica; mathematica can do it but I find mathematica better for analytical solutions.

My advice is just make the fit in excel and get an equation for Y, then plug that into mathematica to get an expression for u.

 DaleSpam Apr19-11 08:32 PM

Quote:
 Quote by aminbkh (Post 3256001) Thanks ,actually you cant do that because as I told you this a coupled equation,I apology because in formula I forgot something the second formula is something like this 1-u*Y=u(1-u/Y^.4)^.5*Y^.45 and then I should put this in this equation F=T*Y^(0.5). now could you please me tell what to do.I appreciate it.
When you do a fit you need to have more unknowns than equations. For example, if you do a simple linear regression you have an equation of the form y=mx+b where x and y are known (your data points) and m and b are unknown. So you have one equation in two unknowns and you do fitting.

In your case T and F are knowns and u and Y are unknowns. You have two equations in two unknowns, so you cant do fitting, there is nothing to fit, you just solve the equations. The only thing close to a "fit" that you can do in this case is to average the results.

 a-tom-ic Apr20-11 12:33 PM

Not solving your question, just typing your equations like i would on paper, to be sure you get your initial equations communicated to us (and for easier viewing), please check if i made an error:

$$f=t\cdot\sqrt{y}$$
$$1-\left(u \cdot y\right)=u \cdot y^{0.45} \cdot \sqrt{1-\frac{u}{y^{0.4}}}$$

Again with your statement from your first post, "i got f and t from experimental data" you should already be able to solve equation (1) for y, right?

 aminbkh Apr20-11 09:20 PM

Yes.I apology again I forget a very Important one let me write the exact equation,just because I wanted to simplify it I made mistake the exact equation is:

1-(1-u)*Y=u(1-a/(t*Y^.32))^0.5*Y^.45

so this one is exact one as you can see the y depeds on T and u.actually I solve my problem
in just by hand.I am seeking to alternative way.it is important for me
once again I apologies for my mistake,I really appreciate it

 DaleSpam Apr21-11 06:32 AM

OK, here is the process:
1) solve the first equation for y
2) substitute into the second equation
3) solve the second equation for f to get an expression for f in terms of t, a, and u
4) put your data in the form {{t1,f1},{t2,f2},...}
5) use FindFit[data,expr,{a,u},{t}]

 aminbkh Apr21-11 02:57 PM

I write this small program in mathematica
F[p_, k_] :=
Block[{y}, Solve[k*y - 1 == 0, y];
p^2*y]
but when I write this
F[.2, .4]
I get
0.04 y
Do somebody know where I made mistake?
thanks

 DaleSpam Apr21-11 03:41 PM

Yes, you forgot to substitute the expression for y into the output expression.

 aminbkh Apr21-11 08:00 PM

thank you

 DaleSpam Apr22-11 06:16 AM

In the first line you solved for y, but then you never did anything with that solution. You didn't set y to anything. So when it came time to evaluate the second line y had not changed and was just left as the symbol y. You can fix that one of two ways:

F[p_, k_] :=
Block[{y}, p^2*y /. Solve[k*y - 1 == 0, y]]

or

F[p_, k_] :=
Block[{y}, y=1/k;
p^2*y]

In the first one you set the value of y by substitution (/.), and in the second you set the value of y directly (=).

 aminbkh Apr22-11 08:09 AM

thank you

 aminbkh Apr22-11 11:56 PM

Hi
what is meaning of this term in [Block]for example:
f[,]=Block[variable{},...]

what is meaning of {} here for variable

thank you

 DaleSpam Apr23-11 08:09 AM

The {} simply denotes a list. Mathematica uses very consistent notation, [] always denotes function arguments, () always denotes operator precedence.

 aminbkh Apr24-11 10:15 AM

I have defined this function
F[p_, k_] :=
Block[{y},
p^2*y /. Solve[k*y - 1 == 0, y]]
I want to minimize it, so I write:

Minimize[F, k] and the answer is
{F, {k -> 0}}
I know I can write it very simply.
But I want to know where I made mistake in this way of writing.
Thank you

 DaleSpam Apr24-11 11:34 AM

Remember that F is not defined. What is defined is F[_,_]. Since F is not defined it is not a function of k and all values of k qualify as a minimum.

 aminbkh Apr24-11 11:52 AM