Trouble with using the command WhenEvent in Mathematica

  • #1
Youssi
6
2
TL;DR Summary
Mathematic, error in using the command WhenEvent in Mathematica

Reference: https://www.physicsforums.com/forums/matlab-maple-mathematica-latex.189/post-thread
Hello, I'm trying to solve a heat differential equation to obtain the temperature distribution as a function of R. Since I have the coefficients of electrical and thermal conductivity that start from the temperature of 6500 K, I want the solution to stop when T reaches 6500. I'm using the command:

Code:
 WhenEvent[T[r] >= 6500, {RlimiteValue = r, "StopIntegration"}].

However, I'm encountering the following errors:

Code:
`Plot::plln: Limiting value RlimiteValue in {r, 1/10000000000, RlimiteValue} is not
a machine-sized real number.

Can someone help me resolve this issue?

Thank you in advance for your assistance

The program is listed below :
Code:
ClearAll["Global`*"]

(*Importation des coéfficient non linéaire : conductivité thermique et conductivité thermique*)

Lambda=Import["C:\\Users\\yousra\\Documents\\thèse\\Modélisation\\1_mathematica\\condu_therm_rer.xlsx"][[1]];
Sigma=Import["C:\\Users\\yousra\\Documents\\thèse\\Modélisation\\1_mathematica\\condu_elec.xlsx"][[1]];

(*Interpolation et création des fonctions de Lamdba et sigma*)

(*Lambda*)

λInterp=Interpolation[Lambda,InterpolationOrder->1];

(*Définir la fonction λ(t)*)

Clear[λ];
λ[t_]:=λInterp[t];

(*Vérifier la fonction λ(t) pour quelques valeurs de t*)

λ[3000];
λ[700];
λ[12000];

(*sigma*)

σInterp=Interpolation[Sigma,InterpolationOrder->1];

(*Définir la fonction σ(t)*)

Clear[σ];
σ[t_]:=σInterp[t];
σ[3000];

(*Dessin de lambda et sigma interpolé*)

(*Tracer la fonction λ(t)*)

Plot[λ[t],{t,Min[Lambda],Max[Lambda]},AxesLabel->{"t","λ(t)"},PlotLabel->"Plot of λ(t)"]

(*Tracer la fonction σ(t)*)

Plot[σ[t],{t,Min[Sigma],Max[Sigma]},AxesLabel->{"t","σ(t)"},PlotLabel->"Plot of σ(t)"]

(*l'équation de chaleur*)

Equ1=Div[λ[T[r]]*Grad[T[r],{r,θ,z},"Cylindrical"],{r,θ,z},"Cylindrical"]+σ[T[r]]*F^2==0//FullSimplify
F=6000;
Tmax=29000;

(*sol=NDSolve[{Equ1,T'[0]==0,T[0]==10000,T[10^-2]==6000},T,{r,0,10^-2}][[1]];
Plot[T[r]/. sol,{r,0,10^-2},AxesLabel->{"r","T(r)"},PlotLabel->"Graphique de T en fonction de r"]*)

(*Define the solution*)
(*Define the solution*)
(*Define the solution*)

sol=NDSolveValue[{Div[λ[T[r]]*Grad[T[r],{r,θ,z},"Cylindrical"],{r,θ,z},"Cylindrical"]+σ[T[r]]*F^2==0,
    T'[10^-10]==0,
    T[10^-10]==Tmax,
    WhenEvent[T[r]>=6500,{RlimiteValue=r,"StopIntegration"}]},
    T,{r,10^-10,10^-2}];

(*Print the result*)

Print["Rlimite corresponding to T >= 6500: ",RlimiteValue]

(*Plot the solution up to the RlimiteValue*)

Plot[sol[r], 
    {r, 10^-10, RlimiteValue}, 
    AxesLabel -> {"r", "T[r]"},
    PlotLabel -> "Solution up to RlimiteValue"]

Plot[sol[r],
    {r,10^-10,RlimiteValue},
    AxesLabel->{"r","T[r]"},
    PlotLabel->"Solution up to RlimiteValue"]
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
I'm not familiar with Mathematica and until someone who is responds, I thought I'd provide something to help you along:
The error you're encountering seems to be related to the fact that RlimiteValue is not being assigned a numerical value before it's used in the plotting function. WhenEvent stores the value of r where the condition T[r]>=6500 is met in RlimiteValue, but if the condition is never met, RlimiteValue remains undefined and cannot be used as a plot limit.

Also check on the Mathematica website using your error message as a search term to see what pops up. I got the following:

http://forums.wolfram.com/mathgroup/archive/1997/Oct/msg00331.html

and

https://mathematica.stackexchange.com/questions/170024/is-not-a-machine-sized-real-number
 
Last edited:
  • Like
Likes Youssi
  • #3
Thank you very much! I simply provided an initial value for RlimiteValue, and it worked.
 
  • Like
Likes jedishrfu

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
227
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top