Physics Forums

Physics Forums (http://www.physicsforums.com/index.php)
-   Math & Science Software (http://www.physicsforums.com/forumdisplay.php?f=189)
-   -   Question about Mathematica (http://www.physicsforums.com/showthread.php?t=491565)

aminbkh Apr19-11 12:43 AM

Question about Mathematica
 
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

Re: Question about Mathemtica
 
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

Re: Question about Mathemtica
 
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

Re: Question about Mathemtica
 
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

Re: Question about Mathemtica
 
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

Re: Question about Mathemtica
 
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:

Your first equation: (1)
[tex]f=t\cdot\sqrt{y}[/tex]
Your second equation: (2)
[tex]1-\left(u \cdot y\right)=u \cdot y^{0.45} \cdot \sqrt{1-\frac{u}{y^{0.4}}}[/tex]

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

Re: Question about Mathemtica
 
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

Re: Question about Mathemtica
 
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

Re: Question about Mathemtica
 
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

Re: Question about Mathemtica
 
Yes, you forgot to substitute the expression for y into the output expression.

aminbkh Apr21-11 08:00 PM

Re: Question about Mathemtica
 
could please you explain more?
thank you

DaleSpam Apr22-11 06:16 AM

Re: Question about Mathemtica
 
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

Re: Question about Mathemtica
 
thank you

aminbkh Apr22-11 11:56 PM

Re: Question about Mathemtica
 
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

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

aminbkh Apr24-11 10:15 AM

Re: Question about Mathemtica
 
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

Re: Question about Mathemtica
 
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

Re: Question about Mathemtica
 
Hi,
Thank you , but I think I define it before,when I inserted F[p_,k_].

could you please explain more how can I get correct result by this way?
Thank you very much


All times are GMT -5. The time now is 03:20 AM.

Powered by vBulletin Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2014 Physics Forums