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

  • Mathematica
  • Thread starter aminbkh
  • Start date
  • Tags
    Mathematica
In summary: 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.
  • #1
aminbkh
24
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
  • #2


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:
  • #3


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


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


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:
  • #6


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


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


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}]
 
  • #9


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


or I used this one too but I didn't get answer:

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

Minimize[F[.1, u], {u}]
 
  • #32


I would suggest that you try a simple function that you know the answer first, and make sure that your code works for the simple case. Only then make it complicated.
 
  • #33


Hi,
As you said I did that. The code seems to be correct and logical but I don't know where I am making mistake could you please advise me in this respect?
thanks
B[t_, Y_] := t*Y
F[t_, u_] := Block[{Y}, B[t, Y] /. FindRoot[1 - t*Y*u = 0, Y]]
Minimize[F[10, u], u]

I am doing this because in practice the function Y in complicated and I should TABLE it for different t and minimize it
 
  • #34


Why don't you simply post a notebook that has been simplified to contain just enough for someone to be able to easily understand and reproduce your problem and then they can hopefully try to figure out what is wrong with what you are doing?

This endless "I gave it some input, it gave me some output, something is wrong, what do I do" can go on forever.

But it needs to not be 150 kbytes of Mathematica demanding that someone reverse engineer months of undocumented work.
 
Last edited:
  • #35


Hi thanks for your help,I have attached the file
I would appreciate it if you could help me.
 

Attachments

  • problem.nb
    2.5 KB · Views: 484
<h2>1. What is Mathematica and how is it used in scientific research?</h2><p>Mathematica is a computational software program that is widely used in scientific research. It provides a comprehensive set of tools for mathematical and statistical analysis, data visualization, and programming. Mathematica is used by scientists to analyze and interpret data, create models and simulations, and solve complex mathematical problems.</p><h2>2. How can I fit temperature and experimental data in Mathematica?</h2><p>To fit temperature and experimental data in Mathematica, you can use the built-in function "FindFit". This function allows you to specify a model for your data and find the best-fit parameters that minimize the difference between the model and the actual data. You can also use other functions such as "NonlinearModelFit" and "Fit" depending on the complexity of your data and the type of model you are using.</p><h2>3. Can I plot the fitted data in Mathematica?</h2><p>Yes, you can plot the fitted data in Mathematica using the "Plot" function. This function allows you to visualize the fitted data and compare it to the original experimental data. You can also add labels, legends, and customize the plot to make it more informative and visually appealing.</p><h2>4. What are the benefits of using Mathematica for data fitting?</h2><p>There are several benefits of using Mathematica for data fitting. First, it provides a user-friendly interface and a wide range of built-in functions for data analysis and visualization. Second, it allows for easy manipulation and transformation of data, making it suitable for complex data sets. Third, it has powerful statistical and mathematical capabilities, making it a versatile tool for fitting various types of data. Lastly, Mathematica has a large and active community, which means you can easily find support and resources for your data fitting needs.</p><h2>5. Are there any alternatives to Mathematica for data fitting?</h2><p>Yes, there are several alternatives to Mathematica for data fitting, such as MATLAB, R, and Python. Each of these programs has its own strengths and weaknesses, and the choice ultimately depends on your specific needs and preferences. It is recommended to explore and compare different options before deciding on the best tool for your data fitting tasks.</p>

1. What is Mathematica and how is it used in scientific research?

Mathematica is a computational software program that is widely used in scientific research. It provides a comprehensive set of tools for mathematical and statistical analysis, data visualization, and programming. Mathematica is used by scientists to analyze and interpret data, create models and simulations, and solve complex mathematical problems.

2. How can I fit temperature and experimental data in Mathematica?

To fit temperature and experimental data in Mathematica, you can use the built-in function "FindFit". This function allows you to specify a model for your data and find the best-fit parameters that minimize the difference between the model and the actual data. You can also use other functions such as "NonlinearModelFit" and "Fit" depending on the complexity of your data and the type of model you are using.

3. Can I plot the fitted data in Mathematica?

Yes, you can plot the fitted data in Mathematica using the "Plot" function. This function allows you to visualize the fitted data and compare it to the original experimental data. You can also add labels, legends, and customize the plot to make it more informative and visually appealing.

4. What are the benefits of using Mathematica for data fitting?

There are several benefits of using Mathematica for data fitting. First, it provides a user-friendly interface and a wide range of built-in functions for data analysis and visualization. Second, it allows for easy manipulation and transformation of data, making it suitable for complex data sets. Third, it has powerful statistical and mathematical capabilities, making it a versatile tool for fitting various types of data. Lastly, Mathematica has a large and active community, which means you can easily find support and resources for your data fitting needs.

5. Are there any alternatives to Mathematica for data fitting?

Yes, there are several alternatives to Mathematica for data fitting, such as MATLAB, R, and Python. Each of these programs has its own strengths and weaknesses, and the choice ultimately depends on your specific needs and preferences. It is recommended to explore and compare different options before deciding on the best tool for your data fitting tasks.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
202
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
723
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
3K
Back
Top