Mathematica - using rules to assign integration limits

In summary, Bill is trying to find the integration of his function f[x] from 1 to 4 using the indefinite integral and inserting limits using rules. He is not sure how to insert the limits with rules, has been playing about with the followingIntegrate[f[x], x] /. x -> {1 >= x <= 4}which ain't working, and is looking for another way. He found the FullForm of his expression and solved the problem using replacement rules.
  • #1
izzy93
35
0
I'm trying to find the integration of my function f[x] from 1 to 4 using the indefinite integral and inserting limits using rules. I am not sure how to insert the limits with rules, have been playing about with the following

Integrate[f[x], x] /. x -> {1 >= x <= 4}

which ain't working,

any help much appreciated
 
Physics news on Phys.org
  • #2
How about 1 <= x <= 4?
 
  • #3
Try using some undefined function q, instead of Integrate, that will do nothing at the moment, just to see what actually happens with your substition.

In[1]:= q[f[x],x]/.x->{1≥x≤4}

Out[1]= q[f[{1≥x&&x≤4}],{1≥x&&x≤4}]

and that doesn't look anything like

q[f[x],{x,1,4}]

that I suspect you are trying to accomplish.

So does that provide any additional information for your next attempt?
 
  • #4
Hello Bill,

when I put that in , comes up with an error

ln[106]= q[f[x], x] /. {1 <= x <= 4}
ReplaceAll::reps: {1<=x<=4} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>
out[107] = q[E^(-x/2) x^2 Sin[5 x], x] /. {1 <= x <= 4}

Yes that's what I'm aiming for but I need to do it using rules. Is there another way of going about this?

thanks
 
  • #5
The reason for your latest error is you left out the "x->" that I had. Compare these:
In[1]:= q[f[x],x]/.x->{1≥x≤4}
ln[106]= q[f[x],x] /.{1<=x<=4}

Now if you need to use replacement rules and you need to start with {1<=x<=4} then I would look at

FullForm[{1<=x<=4}]

and see if you can think of a way to use rules to turn that into

{x,1,4}

If you can use replacement rules to accomplish that then you will be half way to then using that result as another replacement to turn x into {x,1,4}.

But you have two x that you have to worry about, one inside f[x] and one inside q[ ,x]. You only want to replace the second one, not the first one.

You might look at this
http://reference.wolfram.com/mathematica/ref/Replace.html
and pay particular attention to levelspec. Levels are not exactly obvious to a new user, but with the hint that you want to pay attention to that then you might be able to figure out how to have a replacment only change the particular x that you are wanting it to and leave the other x alone.

So look at that FullForm result and see if you can solve that problem first. Then you can study levels.
 
  • #6
In[32] = q[f[x], x] /. x -> {1 <= x <= 4}
out[30]=q[{E^(-(1/2) (1 <= x <= 4)) (1 <= x <= 4)^2 Sin[
5 (1 <= x <= 4)]}, {1 <= x <= 4}]
which just substitutes in what I want the limits of x to be

In[1] = FullForm[{1 <= x <= 4}]
Out[2] = List[LessEqual[1,x,4]]

then I tried

In[3]= FullForm[{x >= 1, x <= 4}]
out[4] = List[GreaterEqual[x,1], LessEqual[x,4]]

Afraid I can't see how to turn it into {x,1,4}, is quite beyond me atm!

thanks
 
  • #7
In[1]:= {1≤x≤4}/.{l_<=v_<=h_}->{v,l,h}

Out[1]= {x,1,4}

So that just used your literal input to make a replacement rule.
Sometimes that won't work and sometimes it isn't obvious why.
In those cases you can sometimes use the FullForm of your
expression to make up your replacement rule.
 
Last edited:
  • #8
Ok it's odd but I think I see,
Thanks very much for your help
 

1. How do I use rules to assign integration limits in Mathematica?

To use rules to assign integration limits in Mathematica, you can use the "Assuming" function with the "Integrate" function. Within the "Assuming" function, you can specify the variables and their corresponding limits using the "->" symbol. For example, "Assuming[x>0,x->1,Integrate[x^2,x]]" would integrate x^2 with the limit of 1 for x.

2. Can I assign multiple integration limits using rules in Mathematica?

Yes, you can assign multiple integration limits using rules in Mathematica by separating them with commas within the "Assuming" function. For example, "Assuming[x>0,x->1,y->2,Integrate[x^2+y^2,x]]" would integrate x^2+y^2 with the limits of 1 for x and 2 for y.

3. Is there a way to use rules to assign integration limits for definite integrals in Mathematica?

Yes, you can use rules to assign integration limits for definite integrals in Mathematica by using the "Integrate" function with the "Assuming" function and specifying the limits using the "->" symbol. For example, "Assuming[x>0,x->1,Integrate[x^2,{x,0,2}]]" would integrate x^2 with the limits of 0 and 2 for x.

4. How do I integrate a function with multiple variables using rules in Mathematica?

To integrate a function with multiple variables using rules in Mathematica, you can specify the variables and their corresponding limits within the "Assuming" function, and then use the "Integrate" function with the function and the variables as parameters. For example, "Assuming[x>0,y>0,x->1,y->2,Integrate[x^2+y^2,x,y]]" would integrate x^2+y^2 with the limits of 1 for x and 2 for y.

5. Can I use patterns in rules to assign integration limits in Mathematica?

Yes, you can use patterns in rules to assign integration limits in Mathematica by using the "Assuming" function with the pattern and the corresponding limits specified using the "->" symbol. For example, "Assuming[x>0,x->1,y_*z_+w_->2,Integrate[x^2+y*z+w,x,y,z]]" would integrate x^2+y*z+w with the limits of 1 for x, 2 for y*z, and 2 for w.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
819
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
405
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
255
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
216
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Back
Top