how to write symbolic integral

25 Ansichten (letzte 30 Tage)
Brucedai003
Brucedai003 am 22 Mai 2017
Kommentiert: Star Strider am 22 Mai 2017
I want to use the symbolic function `int` to find the indefinite integral of the function 4*x^2+3, and the definite integral from x = -1 to x = 3. here is my approach, but got an error:
int(4*x^2+3)
int(4*x^2+3, x = -1..3)
>> problem8
Undefined function or variable 'x'.
Error in problem8 (line 1)
int(4*x^2+3)
I followed the documentation of int to write these expressions, but I don't know why it doesn't work, just new to symbolic functions in MATLAB.
Then I reasearched, and added syms x in the first line.Now the first expression works, but the second definite integral still doesn't work.What should I do? Now the error is
syms x
int(4*x^2+3)
int(4*x^2+3, x = -1..3)
>> problem8
Error: File: problem8.m Line: 3 Column: 16
The expression to the left of the equals sign is not a valid target for an assignment.
It's quite awkward of the syntax x = -1..3, not anything like what I learnt in MATLAB.

Akzeptierte Antwort

Star Strider
Star Strider am 22 Mai 2017
Try this:
syms x
int(4*x^2+3)
int(4*x^2+3, x, -1, 3)
ans =
(4*x^3)/3 + 3*x
ans =
26/3
See the documentation for the Symbolic Math Toolbox int function for details.
  2 Kommentare
Brucedai003
Brucedai003 am 22 Mai 2017
Thanks, it works. but I got different answers,
>> syms x
>> int(4*x^2+3, x, -1, 3)
ans =
148/3
And the documentation says
int(4*x^2+3, x = -1..3)
that's why I got confused.
Star Strider
Star Strider am 22 Mai 2017
My pleasure.
Interesting. That syntax is not in the R2017a documentation. It could be in the MuPAD documentation. I did not look there.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!