NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Doing Integrals in C code

November 04, 2010
by vburguess
vburguess's Avatar

I am thinking of a project for my math class and I wanted to basically measure the amount of work on a given spring essentially using a potentiometer but I need to know how to do Integrals, I am a novice in C and it was just an Idea so I was more looking to see how hard it would be to do before I went too far into it and get over my head. Are integrals possible and if so does anyone know where I can get some examples of this.

November 04, 2010
by Ralphxyz
Ralphxyz's Avatar

Here is a very interesting thread about coding integrals http://www.dreamincode.net/forums/topic/54110-integrals/.

I just googled "C integrals".

Apparently it "might" be doable but not much fun.

Ralph

November 04, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi vburguess,

I'm assuming you are not asking whether there is a way you can input a function and have it tell you (symbolically) what the integral of the function is. There are programs that do that, but you don't really want to write one, and you should learn to do them by hand anyway.

I'm assuming what you have is a bunch of measurements coming in, and you want to (numerically) find the integral using the MCU. Fundamentally an integral is just a whole bunch of additions, so it is absolutely possible to do it aboard the MCU. However, you do need to think a little bit about the conversion from the analog real world to a digital world of your MCU. Your physical system is continuous time system, but you are going to be measuring it at discrete intervals. You