Mathematica:How can I acclaim a variable is real in a complex function

In summary, the conversation discusses how to make a function that only outputs real numbers, particularly for the function f[x] := E^(I*x). The solution is to use f[x_]:=Exp[I*Re[x]] which takes the real part of x. The conversation also touches on how to define the domain for the function and how to specify a letter constant as real, pure imaginary, or rational.
  • #1
2
0
Hi,I'm a beginner.
here's the example:
f[x_] := E^(I*x)
Conjugate[f[x]]*f[x]
I'd like get 1,but it give me a complex function coz it regard x as complex.
please help me:how to claim x is real?

by the way,is that necessary to define a letter as a constant.no matter yes or not,how to refer a letter constant to be real or pure imaginary

Thank you!
 
Last edited:
Physics news on Phys.org
  • #2
You could do
Code:
f[x_]:=Exp[I*Re[x]]
so it takes only the real part of x (which doesn't change it, of course, when x is real).
 
  • #3
Thanks for your reply.
I tried your answer,and it works.

Well,I have some...eerr...
what if I'd define the domain for function f[x]?
I mean that I want to prescribe x in f[x] must be real or pure imaginary or rational number.How to do that.

I've a similar question here.How to claim a letter constant to be real or pure imaginary or rational number?

Waiting for your kindness.
 
Last edited:

1. How do I declare a variable as real in a complex function?

You can use the function "Assuming" to declare a variable as real in a complex function. For example, Assuming[x ∈ Reals, f[x]] will assume that the variable x is a real number in the function f[x].

2. What if my complex function has multiple variables? Can I declare them all as real?

Yes, you can declare multiple variables as real by using the "Assuming" function with the "And" operator. For example, Assuming[x ∈ Reals && y ∈ Reals, f[x,y]] will assume that both x and y are real numbers in the function f[x,y].

3. Can I declare a variable as complex in a real function?

Yes, you can use the "ComplexExpand" function to convert a real function into a complex one. For example, ComplexExpand[f[x], TargetFunctions -> {Re, Im}] will convert the function f[x] into a complex function with real and imaginary parts.

4. How do I check if a variable is declared as real in a complex function?

You can use the function "Element" to check if a variable belongs to a specific set, such as the set of real numbers. For example, Element[x, Reals] will return "True" if the variable x is declared as a real number.

5. Can I change the variable type after it has been declared in a complex function?

Yes, you can use the function "Refine" to change the type of a variable in a complex function. For example, Refine[x, x ∈ Reals] will change the type of the variable x from complex to real in the function f[x].

Similar threads

  • Calculus and Beyond Homework Help
Replies
17
Views
1K
  • Calculus and Beyond Homework Help
Replies
27
Views
412
Replies
4
Views
975
Replies
3
Views
1K
Replies
6
Views
723
Replies
4
Views
643
Replies
1
Views
445
  • Differential Equations
Replies
3
Views
2K
Replies
15
Views
2K
Replies
36
Views
3K
Back
Top