Mathematica How to Use a Function in a Loop in Mathematica?

AI Thread Summary
The discussion focuses on using functions within loops in Mathematica, specifically for Hermite's polynomial calculations. A user inquires about accessing a function A(i) within a loop and receives guidance on creating a list of functions to facilitate this. Examples demonstrate how to define functions and use them in summation expressions effectively. The user acknowledges the advice and confirms understanding of how to implement functions in loops. Overall, the thread emphasizes the importance of organizing functions in lists for iterative processes in Mathematica.
ggeo1
Messages
61
Reaction score
0
Hello, i have this formula to iterate(attached).
It is hermite's polynomial .

I wanted to ask if in order to access Ai(x) , where A is another function ,

can i do this ?

Code:
...
suma = 0; sumb = 0;
For[i = 1, i <= n, i++,
 suma +=[B][SIZE="4"] a[x][[i]][/B]*Cos[Pi*x] ;    (a is A)
 sumb += b[x][[i]]*D[Cos[Pi*x], x];
...
 

Attachments

  • image.png
    image.png
    1.3 KB · Views: 524
Physics news on Phys.org
If A really is a list of functions, perhaps something like this might work:

In[8]:=af1[x_]:=Cos[x];af2[x_]:=2*Sin[x];a={af1,af2};a[[1]][x]+a[[2]][x]
Out[8]=Cos[x]+2 Sin[x]

Then this might work:
In[4]:=n=2;
af1[x_]:=Cos[x];af2[x_]:=2*Sin[x];a={af1,af2};
bf1[x_]:=Tan[x];bf2[x_]:=Exp[x];b={bf1,bf2};
suma=Sum[a[][x]*Cos[Pi*x],{i,1,n}];
sumb=Sum[b[][x]*D[Cos[Pi*x],x],{i,1,n}];
 
Last edited:
Ok ,thanks ,i will check it.

It must be right.I didn't know how to put a function into a loop.But ,as you did,you must make a list of the function in order to do that.

Thanks again!
 

Similar threads

Replies
1
Views
2K
Replies
13
Views
2K
Replies
2
Views
2K
Replies
12
Views
5K
Replies
4
Views
2K
Replies
2
Views
2K
Replies
4
Views
3K
Back
Top