# Integrals In Vexcode

What’s up people,

I was wondering if there is a way to use the integral function in CPP or particularly, in Vexcode. Is there a library we’d have to import? If so how do we import this library into vexcode. Thanks and have a great day.

It depends on your application. Indefinite integrals are very difficult to solve computationally and would probably require you to implement the Risch Algorithm (aka not fun). Definite integrals can be estimated using Riemann Sums, this is your best bet.

There are examples of how to do this in the December 2019 products thread (in the context of integrating acceleration into position)

4 Likes

I plan to find the length of a curve using a definite integral. I don’t plan to use the integrals for the new sensor. Is this feasible? Is there a program I could import with riemann sums?

using Riemann sums isn’t that difficult, you can just program it to multiply the sensor value by the amount of time between the last measure.

What kind of curves? Are these measured or produced in advance from a formula you know ahead of time? If you’re producing them, are they always the same type?

What I’m trying to get at is that your problem likely isn’t “how do I integrate with C++” but is more likely “how do I find the arc length of _______”. See: the XY problem. Make sure you always talk about the original problem that you’re trying to solve, not just the secondary problem you ran into while trying to solve the first problem.

5 Likes

so I’ve hit a similar problem with a cosine segment and do have the definite integral formula to calculate the arc length however don’t know how to use a integral in c++ as it has no CAS library or something similar to my knowledge

Yah so the basic problem is calculating the length of a curve, wher I am modifying the equation for this curve before hand. I know the equation, it’s the same everytime except for the height, width, and endpoints.

Is it a secret?

5 Likes

He just probably wasnt looking to share it on such a public forum since its clearly a more advanced topic that he wanted to keep to his team

It could be an equation not heretofor known to man. Super secret.

1 Like

Nah it’s just the length of a cosine graph on the range of -pi/2 to pi/2 but i’d be modifying the equation to alter the amplitude and height

There’s no reason to try and do actual integration on the V5 Brain for that. Do the integration by hand with variables like k in place of any constants that might change, and in your code just plug in numbers for k in your final, simplified formula.

That way, all you need to do in your code is basic arithmetic.

5 Likes

And when all else fails, Taylor series exist.

1 Like