How to Use a Function in a Loop in Mathematica?

In summary, the speaker has a formula for Hermite's polynomial and wants to know how to access the function Ai(x), which is another function represented by A. The expert suggests creating a list of the functions and using a loop to access them. The speaker thanks the expert for their help.
  • #1
ggeo1
63
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]][/SIZE][/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: 469
Physics news on Phys.org
  • #2
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:
  • #3
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!
 

What is the "Sum" function in Mathematica?

The "Sum" function in Mathematica is a built-in function that allows you to find the sum of a series of terms. It can be used to find the sum of a list of numbers, a series of mathematical expressions, or even an infinite series.

How do I use the "Sum" function in Mathematica?

To use the "Sum" function in Mathematica, you need to specify the series of terms you want to sum, as well as the variable of summation and the limits of the summation. For example, Sum[n, {n, 1, 10}] would sum the numbers from 1 to 10.

Can the "Sum" function handle complex numbers?

Yes, the "Sum" function in Mathematica can handle complex numbers. You just need to make sure to use the ComplexExpand function to simplify any complex terms before using the "Sum" function.

Can I use conditions with the "Sum" function in Mathematica?

Yes, you can use conditions with the "Sum" function in Mathematica by using the /; symbol. For example, Sum[n^2, {n, 1, 10, n /; n>5}] would sum the squares of numbers from 1 to 10, but only for values of n greater than 5.

Is there a way to speed up the "Sum" function in Mathematica?

Yes, there are several ways to speed up the "Sum" function in Mathematica. You can use the Compile function to compile the summation, use the ParallelSum function to distribute the summation across multiple processors, or use the Method option to choose a specific summation algorithm.

Similar threads

Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
810
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
240
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
546
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
Back
Top