MATLAB Answers

vector gives 0 integral

11 views (last 30 days)
Gavin Seddon
Gavin Seddon on 28 Jul 2021
Commented: Star Strider ungefär 19 timmar ago
Hello
I have plotted a vector which has 3 planes.. When I integrate the integral is 0. There are negative regions, yet I expect a number. I us
sd = trapz((z),0,20)
sd =
0
will someone tell me if there is an error with my use of trapz?
sr

Accepted Answer

Star Strider
Star Strider on 28 Jul 2021
There quite definitely is!
In your call to it:
sd = trapz((z),0,20)
the function interprets ‘z’ (the parentheses aren’t necessary) as the indepdent variable ‘x’, 0 as the dependent variable ‘y’, and 20 as the dimension. Integrating 0 produces 0 as the result.
See the documentation on trapz.
.
  12 Comments
Star Strider
Star Strider ungefär 19 timmar ago
As always, my pleasure!
You can use syms if you wish, however I see no significant advantage to doing that.
syms x
int_y = int((x*6.4985e-4-x^2*2.8208e-7+x^3*3.9742e-11+2.4178), x, 0, 5000)
int_y = 
int_y = vpa(int_y, 42)
int_y = 
14668.4791666666669207137336884483073976583
int_y = vpaintegral((x*6.4985e-4-x^2*2.8208e-7+x^3*3.9742e-11+2.4178), x, 0, 5000)
int_y = 
14668.5
.

Sign in to comment.

More Answers (3)

Gavin Seddon
Gavin Seddon on 29 Jul 2021
Hello
Yes John is correct, I tried with no parenth and I see the fun integral not its value which is wht I need.
  4 Comments
Star Strider
Star Strider on 29 Jul 2021
Thank you!
Just curious as to what you are integrating.
.

Sign in to comment.


Gavin Seddon
Gavin Seddon on 29 Jul 2021
Hello
When I searched 'vector integration' the trapezoid method came-up
yet is this correct?

Gavin Seddon
Gavin Seddon on 4 Aug 2021
Hello
I am integrating the number of molecular motions in 10e-15s.

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!