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.

  • #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}]
 
Physics news on Phys.org
  • #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

  • #36


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

If I try this

B[t_, Y_] := Y^(3/4)*t;t = 10; g = Random[Real, {.01, 3}]; u = Random[Real, {.01, 3}];
B[10, Y] /. NSolve[1 - (1 - u)*Y == u*(1 - g/(t*Y^.3))^.5*Y^.32, Y]

just to see how long your innermost step might take, it does not finish in several minutes. That does not give me a good feeling for how long it might take when NMinimize might want to do several hundred or tens of thousands such evaluations looking for a minimum.

When I then do this

Table[1 - (1 - u)*Y - u*(1 - g/(t*Y^.3))^.5*Y^.32, {Y, -10, 10, .1}]

it completes in a fraction of a second and I can see from the result that it does look like that crosses zero. But it looks like trying to understand why your NSolve takes so long is the first thing to do. If that can be fixed then your problem may be solved. But I am a little worried about what will happen in the situation when there is no solution from the NSolve. Then you will be trying to minimize something that is undefined in some domains.

So can you make any progress on speeding up the NSolve step?
 
Last edited:
  • #37


Thank you for your answer.
First most of the time Nsolve should have answer because it has physical meaning.other thing is that Y vary from 0 to 1just between these two number.do you think this make the program faster, at first I used Findroot but it doesn't work for this case.
 
  • #38


Unless there is some physical bound on the value of u it appears that the minimum can become as negative as you like by letting u become as large as you like and finding appropriate values for the other variables.

For example, with 0<Y<1, t=10, 0<g<10
{minvalue, Y, u, g}={-30.8269, 0.173812, 79.9291, 0.0294438} for 0<u<80
{minvalue, Y, u, g}={-62.0829, 0.216682, 158.867, 0.0124873} for 0<u<160
{minvalue, Y, u, g}={-125.834, 0.167075, 319.935, 0.0223538} for 0<u<320
etc.

Each of those were obtained from a very simple fast brute force Monte Carlo run, just to cross check other calculations.

Depending on the range of g and t your 1 - (1 - u)*Y - u*Sqrt[1 - g/(t*Y^.3)]*Y^.32 is complex 10-25% of the time. If that were not the case then a bisection root finder for Y would be simple. It is feasible to calculate the minimum value of Y to ensure that this will be Real with a lower bound on Y of (g/t)^(10/3). With that lower bound on Y bisection seems to work well on your problem.

So are there other constraints on u and g? Or is this appearing to be unbounded the end of your problem?
 
Last edited:
  • #39


Hi,
Thank you for your very helpful answer.I really appreciate it
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · 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