LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-19-2012, 10:57 PM   #1
Melchor
LQ Newbie
 
Registered: Jan 2012
Posts: 2

Rep: Reputation: Disabled
How to evaluate differential equations in c++ using linux compiler.


I'm a master of science in physics student and we have this assignment in finding the position and velocity of a simple harmonic motion using c++. Can anyone help me to make this program using object oriented program?
 
Old 01-20-2012, 12:54 AM   #2
flamelord
Member
 
Registered: Jun 2011
Distribution: Arch Linux
Posts: 151

Rep: Reputation: 34
honestly, I don't see how object oriented programming would give you an advantage in solving a differential equation, and c++ is multi-paradigm, so it doesn't force you to use object oriented programming if it doesn't really fit your problem.

Assuming you are using some variant of the Runge-Kutta algorithm (or Euler's method, though I would recommend against that), I suppose you could make an object that contains the current position and velocity, and pointers or references that point to vectors containing the previous times, positions, velocities, etc. (you probably want to pre-allocate these), and a method that calculates the next position and velocity. You would also have a field for the time step, and a function pointer (or another object) that tells it how to calculate the derivatives at each time step. Actually, now that I think about it, you could make the method that calculates the next time step virtual, so that you could easily make subclasses that change the algorithm. I hope this points you in the right direction.
 
1 members found this post helpful.
Old 01-20-2012, 10:26 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
solve nonlinear differential equations? flamelord Linux - Software 1 09-27-2011 11:52 AM
plotting difference equations which are dependent on linear equations ta0kira Programming 6 11-22-2008 10:08 PM
how to evaluate LINUX i/o Scheduler perfomance? Kotresh Linux - Software 6 03-19-2007 11:09 PM
Running a benchmark to evaluate Linux Cluster asadarfeen Linux - General 2 08-26-2005 11:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration