go_away

### Author Topic: how to implement a differntial equation in C code?  (Read 2920 times)

0 Members and 1 Guest are viewing this topic.

#### robota

• Jr. Member
• Posts: 41
##### how to implement a differntial equation in C code?
« on: August 19, 2008, 07:39:54 AM »
I have a differential equation and I want to implement this in C code
I know that I need to use loops and I know how to implements loop in C code
but I don't know how to do the differential equation
Thanks
robota

#### Iron Man

• Full Member
• Posts: 74
##### Re: how to implement a differntial equation in C code?
« Reply #1 on: August 19, 2008, 09:09:26 AM »
ouch....
did you check math.h?
is there a simpler way for you approximate the solution? Use some fancy algerbra, you know that stuff you learn in highschool?

• Full Member
• Posts: 58
##### Re: how to implement a differntial equation in C code?
« Reply #2 on: August 19, 2008, 01:59:23 PM »
show us the differential equation. Most of the time, you don't even need loops.
It's implentation is fairly simple:

Code: [Select]
`int i = 0;i++; //i is now 1;i += i // i is now 2;i += i // i is now 4;`
Or with loops:
Code: [Select]
`int power(int value, int loops){int numloop;int finalvalue = 0;if (loops > 0) {  finalvalue = 1;  for (numloop = 0; numloop < loops; numloop++) {    finalvalue *= value;  }}return finalvalue;}`
what is the equation you're talking about? I could help you further if I know it. (some background info would be nice too  )

#### robota

• Jr. Member
• Posts: 41
##### Re: how to implement a differntial equation in C code?
« Reply #3 on: August 20, 2008, 12:56:51 PM »
Hallow friends
Iron man I will glad if you can give me more details
Madmax I don't understand the differential equation that your code can solve
I have some differential equation that I want to put in C code and solve it
Like the PID differential equation

Or like other Transfer function

Thanks
robota

#### robota

• Jr. Member
• Posts: 41
##### Re: how to implement a differntial equation in C code?
« Reply #4 on: August 20, 2008, 01:03:51 PM »
I put a better picture

• Full Member
• Posts: 58
##### Re: how to implement a differntial equation in C code?
« Reply #5 on: August 20, 2008, 03:34:41 PM »
well, the definition of a differential equation is: a functions that modifies the original variable inputted. So I understood you wrong.

I do not know what the function does exactly, what are you trying to calculate?
Do you want to retrieve constants from this equation, or should this equation be recalculated every iteration.

For example:
What is Mk or Kp?
Is (K - 1) a timestep?

#### robota

• Jr. Member
• Posts: 41
##### Re: how to implement a differntial equation in C code?
« Reply #6 on: August 20, 2008, 05:30:20 PM »
The PID differential equation is a bad example because I know all the PID "K"s
But the Transfer function example is a good example
I need to find all "y" and all "X" that solve this equation

• Full Member
• Posts: 58
##### Re: how to implement a differntial equation in C code?
« Reply #7 on: August 21, 2008, 02:33:51 PM »
You can't solve it like this. I need to know a certain relation between x and Y.
Please, I need to know what these variables are. How did you come up with this equation?
are x and y places on a plane? I need to know the relation between these two.

Also, how does K+2 modify x or y, where is it refering to.
In physics, this subscript is used to specify where you are talking about,
force is specified by the letter F, if you're talking about gravity, you specify
the force as Fg.

Do you understand why I'm confused?

#### Iron Man

• Full Member
• Posts: 74
##### Re: how to implement a differntial equation in C code?
« Reply #8 on: August 21, 2008, 09:45:32 PM »
math.h is a header file that you can

Code: [Select]
`#include "math.h" `
it helps do many basic functions that allow for easier manipulation of numbers without writing your own functions.

• Supreme Robot
• Posts: 11,632
##### Re: how to implement a differntial equation in C code?
« Reply #9 on: August 22, 2008, 12:02:09 PM »
Are you trying to differentiate an equation, or solve an equation thats been differentiated?

Unless you are designing a calculator, I don't see why you'd want to do the first option . . . the second option is something you can do by hand or using math software . . .

If I was doing calculus on my microcontroller, I'd solve the equation before even programming it in . . .

#### robota

• Jr. Member
• Posts: 41
##### Re: how to implement a differntial equation in C code?
« Reply #10 on: August 22, 2008, 12:51:33 PM »
Madmax I know that I need the initial conditions
But I don't know how to receive this
This differential equation I receive from the transfer function of all the system
But I don't know how I to receive the initial conditions

Iron man I have two big books in C language but in this books I don't have information about math.h
I will glad if there is anybody that have one awesome link that explain math.h to write The link here

Admin this equation have infinite solutions
y0, y1, y2, y3, y4,,,,,
x0, x1, x2, x3, x4,,,,,
therfore i need to use a math software

robota

• Full Member
• Posts: 58
##### Re: how to implement a differntial equation in C code?
« Reply #11 on: August 22, 2008, 03:13:26 PM »
allright, you state that this equation has infinite solutions.
This means you want to put a computer in an everlasting loop... Or... you need some human like Einstein to solve it for you.
You cannot solve your equation like this, because you do not know what the variables are and you also don't know the relation between x and y

#### Iron Man

• Full Member
• Posts: 74
##### Re: how to implement a differntial equation in C code?
« Reply #12 on: August 25, 2008, 10:54:32 AM »
http://en.wikipedia.org/wiki/Math.h

standard library,

i don't know how much it will be needed, but if there is an trig involved or w/e. idk just throwing it out there.

• Robot Overlord
• Posts: 293