Define parameters accurately in custom functions?

Hi all,

I am new in this forum and hope that some of you can help. I have two questions which are related to eachother. It’s all about defining parameters accurately and I think that I just don’t know how to do this correctly.

General Problem

Assuming the function

f[x_]:=a*x^2

where a is a real number. How can I tell Mathematica that, for example, a is an integer? I found a solution using “Assumptions” as in

Assuming ->  Element[a, Integers]

but this doesn’t work always (for example when I want to solve a system of equations, I got an error). I am looking for an easy solution where I can introduce my variables at the beginning and then use them all the time (the same as how we do it on paper).

One important example that doesn’t work

The next problem (and I think that this is the same as the previous one) is as follows:
I have the same function as above

f[x_]:=a*x^2

Now, I want to use the manipulation function as in

Manipulate[Plot[f[x],{x,-5,5}],{a,1,50}]

When I enter the function itself in the Manipulate argument (instead of “f[x]”), it works. But the way I described it, it doesn’t. Probably, I have to introduce the parameter a, but I just don’t know how.

Is something like this possible?

To illustrate my problem, another example:

When I enter

a=10

and

b=20

the command

Plot[x^2,{x,a,b}]

works perfectly. Now, I want to enter something like

a,b=real

Thanks in advance for the answers.

Hey, Christian, how are you?

You can do

f[a_Integer,x_Real]:=a*x^2

so, when you use manipulate, you will be able to run the following code

Manipulate[Plot[f[a,x],{x,-5,5}],{a,1,50,1}]

Hello Estevao,

Thank you so much for your reply! It works perfectly, however, do you also have a solution where I can define the parameter globally? In a way, that I can define a as an integer and use this to define several functions? Or do I have to enter every time I use the parameter that this is an integer?

Thank you so much!

Im not sure but naybe you could use some assumptions.
https://reference.wolfram.com/language/guide/AssumptionsAndDomains.html

check also

https://mathematica.stackexchange.com/questions/66273/how-to-tell-mathematica-that-certain-variables-are-real-imaginary-integer-value

https://mathematica.stackexchange.com/questions/118955/how-to-assume-all-variables-in-my-code-are-reals

Hello Estevao,

thank you so much for helping!