How to call a built function in mathematica

Reem Hashem
Messages
23
Reaction score
0
Hello,I need somebody to help me in Mathematica programm
I wrote code that works as a function which I can call when I need in another function, but it did not work ,so I need help how to call my function
and thanks in advance
 

Attachments

Physics news on Phys.org
Your code is much too complicated. You need to break it down into simpler steps, and then try it on simpler examples, to find where the error lies.
 
In[1]:= tmp[a_, z_, w_] := Module[{m, f, d, b},
m = NDSolve[{
y1'[t] == y5[t], y2'[t] == y6[t], y3'[t] == y7[t], y4'[t] == y8[t],
y5'[t] == y9[t], y6'[t] == y10[t], y7'[t] == y11[t], y8'[t] == y12[t],
y9'[t] == y13[t], y10'[t] == y14[t], y11'[t] == y15[t], y12'[t] == y16[t],
y13'[t] == -z^4 y1[t] + 2 z^2 y9[t] + z^2 w (-t + t^2) y17[t] + a y9[t],
y14'[t] == -z^4 y2[t] + 2 z^2 y10[t] + z^2 w (-t + t^2) y18[t] + a y10[t],
y15'[t] == -z^4 y3[t] + 2 z^2 y11[t] + z^2 w (-t + t^2) y19[t] + a y11[t],
y16'[t] == -z^4 y4[t] + 2 z^2 y12[t] + z^2 w (-t + t^2) y20[t] + a y12[t],
y17'[t] == y21[t], y18'[t] == y22[t], y19'[t] == y23[t], y20'[t] == y24[t],
y21'[t] == (-1 + 2 t) y1[t] + z^2 y17[t] - a y29[t],
y22'[t] == (-1 + 2 t) y2[t] + z^2 y18[t] - a y30[t],
y23'[t] == (-1 + 2 t) y3[t] + z^2 y19[t] - a y31[t],
y24'[t] == (-1 + 2 t) y4[t] + z^2 y20[t] - a y32[t],
y25'[t] == y29[t], y26'[t] == y30[t], y27'[t] == y31[t], y28'[t] == y32[t],
y29'[t] == -y21[t] + z^2 y25[t], y30'[t] == -y22[t] + z^2 y26[t],
y31'[t] == -y23[t] + z^2 y27[t], y32'[t] == -y24[t] + z^2 y28[t],
y1[0] == y2[0] == y3[0] == y4[0] == y5[0] == y6[0] == y7[0] == y8[0] ==
y10[0] == y11[0] == y12[0] == y13[0] == y15[0] == y16[0] == y17[0] ==
y18[0] == y19[0] == y20[0] == y21[0] == y22[0] == y24[0] == y25[0] ==
y26[0] == y27[0] == y28[0] == y29[0] == y30[0] == y31[0] == 0,
y9[0] == y14[0] == y23[0] == y32[0] == 1}, {y1, y2, y3, y4, y5,
y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18,
y19, y20, y21, y22, y23, y24, y25, y26, y27, y28, y29, y30, y31,
y32}, {t, 0, 1}];
f[1, 1] = y1[1] /. m;
f[1, 2] = y2[1] /. m;
f[1, 3] = y3[1] /. m;
f[1, 4] = y4[1] /. m;
f[2, 1] = y5[1] /. m;
f[2, 2] = y6[1] /. m;
f[2, 3] = y7[1] /. m;
f[2, 4] = y8[1] /. m;
f[3, 1] = y17[1] /. m;
f[3, 2] = y18[1] /. m;
f[3, 3] = y19[1] /. m;
f[3, 4] = y20[1] /. m;
f[4, 1] = y25[1] /. m;
f[4, 2] = y26[1] /. m;
f[4, 3] = y27[1] /. m;
f[4, 4] = y28[1] /. m;
d = Array[f, {4, 4}];
d = Partition[Flatten[d], 4];
b = Det[d]];
tmp[0, 3.7, 1000]

Out[2]= 15.7127
 
Thank you Mr Bill for your Help ,this what I need,but now I want to know how to call this function in FindRoot function to get the value of w,I tried to do it but it did not work,I wort FindRoot[temp[0,3.7,w_],{w,1000,100000}]
and thanks in advance.
 
You will have a lot less trouble trying to write Mathematica if you understand how to use and not use the _ in your code.

This might help.
http://reference.wolfram.com/mathematica/tutorial/DefiningFunctions.html

This
Plot[tmp[0, 3.7, w], {w, 1000, 100000}]
shows how your function behaves.

But this
FindRoot[tmp[0, 3.7, w] == 0, {w, 95000, 90000, 100000}]
fails for some reason I haven't been able to isolate in your code.

This
Plot[tmp[0, 3.7, w], {w, 90000, 95000}]
can give you a good estimate.
 
Thread 'Direction Fields and Isoclines'
I sketched the isoclines for $$ m=-1,0,1,2 $$. Since both $$ \frac{dy}{dx} $$ and $$ D_{y} \frac{dy}{dx} $$ are continuous on the square region R defined by $$ -4\leq x \leq 4, -4 \leq y \leq 4 $$ the existence and uniqueness theorem guarantees that if we pick a point in the interior that lies on an isocline there will be a unique differentiable function (solution) passing through that point. I understand that a solution exists but I unsure how to actually sketch it. For example, consider a...

Similar threads

Back
Top