Reputation: 57
I would like to make a 3d plot of a function that takes as a variable a function of another variable.
The whole thing is complicated by the fact that my functions are nested piecewise functions
here is my code:
phi0=Function[u,1.21*10^-6/((u/10^44.25)^1.01 + (u/10^44.25)^2.38)][Lx]
zc=Function[v,Piecewise[{{2.49,v>=10^45.74},{2.49*(v/10^45.74)^0.2,v<10^45.74}}]][Lx]
e=Function[uu,Piecewise[{{(1+uu)^4.62,uu<=zc},{(1+zc)^4.62*((1+uu)/(1+zc))^-1.15,uu>zc}}]][z]
Plot3D[e[z,Lx],{z,0,7},{Lx,10^42,10^47}, PlotRange->Full]
but it is not plotting anything, and I am not sure of what to do
EDIT:
thanks, for the hint, I think I solved it this way. It is not giving me any error, but it is taking a lot of time to evaluate the result even in one single point... do you think it is normal?
phizero[Lx_] := 1.21/10^6/((Lx/10^44.25)^1.01 + (Lx/10^44.25)^2.38)
zc[Lx_] :=
Piecewise[{{2.49, Lx >= 10^45.74}, {2.49*(Lx/10^45.74)^0.2,
Lx < 10^45.74}}]
e[z_, Lx_] :=
Piecewise[{{(1 + z)^4.62,
z <= zc[Lx]}, {(1 + zc[Lx])^4.62*((1 + z)/(1 + zc[Lx]))^-1.15,
z > zc[Lx]}}]
phi[z_, Lx_] := phizero[Lx]*e[z, Lx]
(*D[phi[z,Lx],Lx]:=Lx*phi[z,Lx]*)
p[z_, Lx_] = Integrate[Lx*phi[z, Lx], Lx]
p[4, 10^44]
Upvotes: 0
Views: 590
Reputation: 6999
It is taking a long time because it works hard to symbolically integrate the function. It takes a while just to learn it cant be done. -- use NIntegrate for numerical integration. Here is a stab at it.. notice as a good habit i leave out the floating point values from the expressions until really needed:
constants = {c1 -> 10^45.74, c2 -> 10^44.25, c3 -> 2.49, c4 -> 4.62,
c5 -> 2.38, c6 -> 0.2, c7 -> 1.21/10^6, c8 -> -1.15, c9 -> 1.01}
phizero[Lx_] := c7/((Lx/c2)^c9 + (Lx/c2)^c5)
zc[Lx_] := Piecewise[{{c3, Lx >= c1}, {c3 (Lx/c1)^c6, Lx < c1}}]
e[z_, Lx_] :=
Piecewise[{{(1 + z)^c4,
z <= zc[Lx]}, {(1 + zc[Lx])^c4 ((1 + z)/(1 + zc[Lx]))^c8,
z > zc[Lx]}}]
phi[z_, Lx_] := phizero[Lx] e[z, Lx]
p[z_, L1_, L2_] := NIntegrate[Lx phi[z, Lx] /. constants, {Lx, L1, L2}]
p[4, 10^42, 10^47]
quickly returns:
(* ~7 10^84 *)
Upvotes: 0
Reputation: 3977
First, Function works like this:
In[1]:= q = Function[x, x^2];
In[2]:= q[4]
Out[2]= 16
so lose the [var] that you have at the end of each of your Function definitions. You could also do
q[x_]:= x^2
and skip the use of Function[] if that would be simpler.
Next, you define the function e to accept a single argument, but then you give it two arguments when you use it inside your Plot3D. So you need to figure out what your definition of the function e should be and I can't even guess how to do that.
Upvotes: 1