How to call a built function in mathematica

  • #1
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

Answers and Replies

  • #2
Avodyne
Science Advisor
1,396
88
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.
 
  • #3
1,069
29
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
 
  • #4
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.
 
  • #5
1,069
29
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.
 

Related Threads on How to call a built function in mathematica

Replies
0
Views
1K
Replies
3
Views
4K
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
6
Views
11K
Replies
1
Views
2K
  • Last Post
Replies
8
Views
2K
  • Last Post
Replies
6
Views
2K
Replies
2
Views
2K
Replies
1
Views
5K
  • Last Post
Replies
2
Views
4K
Top