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

  • Thread starter Thread starter aminbkh
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary
The discussion revolves around fitting experimental data in Mathematica using coupled equations to derive the variable u. Users are advised that instead of fitting, they can solve for u directly by eliminating Y from the equations. A user encountered issues while trying to implement a function in Mathematica, leading to confusion over the correct use of operators and function definitions. The conversation highlights the importance of clearly defining functions and understanding the behavior of numerical solvers like NSolve and FindRoot in Mathematica. Ultimately, users are encouraged to simplify their problems for better troubleshooting and efficiency in finding solutions.
  • #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 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 19 ·
Replies
19
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K