# Problem with using Integrate and Plot functions [closed]

I'm pretty new to Mathematica. I'm trying to implement the following 2 lines:

f[x_] := Integrate[2 x, {x, 0, R}, Assumptions -> R >= 0]

Plot[f[x], {x, 0, 3}]


When I run them, I get the following errors:

Integrate::ilim: Invalid integration variable or limit(s) in {0.0000612857,0,R}.

NIntegrate::itraw: Raw object 0.00006128571428571428 cannot be used as an iterator.

NIntegrate::itraw: Raw object 0.00006128571428571428 cannot be used as an iterator.

Integrate::ilim: Invalid integration variable or limit(s) in {0.0612858,0,R}.

NIntegrate::itraw: Raw object 0.06128577551020408 cannot be used as an iterator.

General::stop: Further output of NIntegrate::itraw will be suppressed during this calculation.

Integrate::ilim: Invalid integration variable or limit(s) in {0.12251,0,R}.

General::stop: Further output of Integrate::ilim will be suppressed during this calculation.


What am I doing wrong here? I tried plotting the function x^2 from 0-3 and got that plot, but I can't get it from the Integrate statement, so can you please tell me what's going on with the code?

Thank you.

## closed as off-topic by Sektor, Coolwater, C. E., LCarvalho, Henrik SchumacherFeb 2 '18 at 9:56

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Sektor, Coolwater, C. E., LCarvalho, Henrik Schumacher
If this question can be reworded to fit the rules in the help center, please edit the question.

• You didn't specify the value of R (naming the upper bound R is a bad idea in its own right; avoid capitals for user-defined functionality). – Sektor Jan 31 '18 at 13:42
• Thanks Sektor... I'm pretty new to Mathematica so forgive me for these things. Thanks again. – Anas Mousa Jan 31 '18 at 14:47

I think what you want can be done with much simpler and more efficient code. First, you must understand that the free variable in the Integrate expression is r not x, so r should be given as the argument for f. Next, for efficiency, you should only do the symbolic integration once, so you should use Set ( = ) in place of SetDelayed ( := ) in your definition of f. When you use SetDelayed the integral is evaluated in the plot at every mesh point.

 f[r_] = Integrate[2 x, {x, 0, r}];

Plot[f[x], {x, 0, 3}]


First of all, plotting what you call $f(x)$ and $f(x)=x^2$ from $0$ to $3$ is not the same thing.

In the former case, you have $R^2$ which is a number -the way you have defined it- and the in latter you have a function of x.

You can make $R$ your variable.

I think that this solves your problem

f[x_] := Integrate[2 x, {x, 0, R}, Assumptions -> R >= 0]

Plot[f[x], {R, 0, 3}]
`

• Thank you Konstantios. – Anas Mousa Jan 31 '18 at 14:48
• No worries. Cheers!!! – Konstantinos Jan 31 '18 at 22:02