Fitting Temperature and Experimental Data in Mathematica: How-To Guide

  • Context: Mathematica 
  • Thread starter Thread starter aminbkh
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary

Discussion Overview

The discussion revolves around fitting experimental data using Mathematica, specifically focusing on the relationship between temperature (T), a variable (Y), and a function (F). Participants explore methods for solving coupled equations and fitting parameters, while also sharing coding issues and alternative approaches.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant presents a coupled equation involving temperature and a variable Y, seeking advice on how to fit parameters using Mathematica.
  • Another participant suggests that fitting may not be necessary and proposes solving for the unknown variable u in terms of known quantities T and F.
  • Some participants express a preference for using MATLAB or Excel for numerical solutions instead of Mathematica, citing ease of use for fitting.
  • There is a discussion about the proper way to substitute variables in Mathematica, with participants providing corrections and clarifications on syntax and function definitions.
  • One participant shares a Mathematica program but encounters issues with variable substitution, prompting others to suggest corrections.
  • Several participants discuss the evaluation of integrals in Mathematica, noting differences in results based on assumptions included in the commands.
  • There are multiple inquiries about the correct usage of functions and operators in Mathematica, with participants seeking clarification on specific coding issues.
  • A participant raises a question about defining derivatives and encounters unexpected results, leading to further discussion on the correct implementation of derivatives in Mathematica.

Areas of Agreement / Disagreement

Participants express differing opinions on the necessity of fitting versus solving equations directly. Some agree that fitting may not be applicable due to the nature of the equations, while others suggest alternative methods for obtaining solutions. The discussion includes multiple unresolved coding issues and varying interpretations of Mathematica syntax.

Contextual Notes

Limitations in the discussion include potential misunderstandings of the equations presented, as well as the complexity of the coding issues raised. Some participants may have differing levels of familiarity with Mathematica, which affects their ability to follow the technical aspects of the conversation.

Who May Find This Useful

This discussion may be useful for individuals working with experimental data analysis in Mathematica, particularly those dealing with fitting parameters, solving coupled equations, or encountering coding challenges in mathematical programming.

aminbkh
Messages
24
Reaction score
0
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
 
Physics news on Phys.org


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.
 
Last edited:


DaleSpam said:
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 can't 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.
 


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.
 


aminbkh said:
Thanks ,actually you can't 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 can't 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.
 
Last edited:


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?
 


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
 


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}]
 


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
 
  • #10


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


could please you explain more?
thank you
 
  • #12


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 (=).
 
  • #13


thank you
 
  • #14


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

what is meaning of {} here for variable

thank you
 
  • #15


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


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
 
  • #17


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.
 
  • #18


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
 
  • #19


To actually minimize the function you need to call

Minimize[F[p,k], k]

Defining F and defining F[_,_] are two different things. In this case F is not defined at all, but F[p,k] is defined and evaluates to {p^2/k}. Do you see the difference?
 
  • #20


Thank you very much.
 
  • #21


HI
I have this very easy Integral but mathmatica can't evaluate it.
could you please tell me why?
thanks
Integrate[Sqrt[c^2 + r^2 - 2*c*r*u], {u, 0, 1}]
 
  • #22


In[1]:= Clear[c,r,u];Assuming[r∈Reals&&c∈Reals,Integrate[Sqrt[c^2+r^2-2*c*r*u],{u,0,1}]]

Out[1]= ((c^2 + r^2)^(3/2) - Abs[c - r]^3)/(3*c*r)

If you do not include the Assuming[] it still finds the integral, but in a much more complicated form with lots of Im[r]*Re[c]... to make the result valid over the complex domain.
 
  • #23


Yes, it evaluates fine for me also.
 
  • #24


Hi
I have written this :
x[T_, Y_] := Y*T + Y^.5*T^2

f[T_, U_] := Block[{X, Y}, X [T, Y] /. Y ;
FindRoot[1 - (1 - U)*Y =
U* Y^(3.5) (1 + 3.14/Y)^.5, {Y, 0.01, 1}]]
f[100, 0.2]

but does not work.could you please help me to know why it doesn't work?
thanks
 
  • #25


Yes. Inside the FindRoot function you need to use the Equal operator (==) instead of the Set operator (=)
 
  • #26


Hi
I have faced another problem I would appreciate it if you could answer me.I defined a derivative but when I differentiate I get wrong result.

Derivative [1][Y] [T_] := Y + Y^2 + 5
A[Y_, T_] := Y^2*T + M*Y
D[A[Y, T], T]

thanks
 
  • #27


Hi all

I have written this statement but it doest work .could you please help me?

Derivative [1][Y] [t_] := Y[t] + Y[t]^2 + 5



Derivative [1][Y] [t_] := Y[t] + Y[t]^2 + 5




z = Y^((23 - 1)/8)
d = Y^(-34/8)
b = Y^(3/8)
v = Y^((8 - 3/8)/8)
x = 4/(5) (Y^(-7/8) - 1)

A[t_, Y_] :=
1/2 t M^2 x*d + U *s *U 8/4! M^4 \x^2 h +
1/5! a*M^5 d^(5/2) v*b +
1/6! 6 M^6 b^3 v^(3/2) +
1/4! 14 t* d*d^2 M^4 x^(1/2)

D[A[Y[t], t], t]
 
  • #28


What part is not working? What are you getting and what are you expecting to get?
 
  • #29


aminbkh said:
A[t_, Y_] :=
1/2 t M^2 x*d + U *s *U 8/4! M^4 \x^2 h +
1/5! a*M^5 d^(5/2) v*b +
1/6! 6 M^6 b^3 v^(3/2) +
1/4! 14 t* d*d^2 M^4 x^(1/2)
Is the bold red backslash (\) supposed to be division? If so, you need to change it to a forward slash (/).
 
  • #30


Hi,
I have faced another problem if you could answer me I would appreciate your kind help.
I have introduced this function
B[t_, Y_] :=
1/2 M^2 Y ^((-1 COMPLICATED FUNCTION OF Y AND t)
then

F[t_, u_] :=
Block[{Y}, t*B[t, Y] /. Solve[1 - (1 - u) Y == Y^2, {Y, 0}]]

Minimize[F[.1, u], {u}]

as can be seen does not work when I want to minimize it with respect to u.
THANKS
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 19 ·
Replies
19
Views
3K