[C con Clase] ayuda codigo c++
ivan ardila
ivanoff01 en gmail.com
Sab Jun 1 22:08:51 CEST 2013
Buenas tardes me pueden hacer el favor y me colaboran con este error RungeKutta4V2.C:37:8: error: expected unqualified-id before numeric constant
RungeKutta4V2.C:44:8: error: expected unqualified-id before numeric constant
este es el codigo
/* From: "COMPUTATIONAL PHYSICS, 2nd Ed"
by RH Landau, MJ Paez, and CC Bordeianu
Copyright Wiley-VCH, 2007.
Electronic Materials copyright: R Landau, Oregon State Univ, 2007;
MJ Paez, Univ Antioquia, 2007; & CC Bordeianu, Univ Bucharest, 2007
Support by National Science Foundation
*/
// Edwin Munevar
// RungeKutta4.C: 4th order Runge-Kutta solution adapted for any kind of acceleration
#include <stdio.h>
#include<iostream>
#include<math.h>
#define N 2 // number of equations: y(t) and v(t)
#define dist 0.1 // stepsize
#define MIN 0.0 // minimum x
#define MAX 200.0 // maximum x
#define b1 0.5 //F=-b1*v
#define a1 0.2 //F=-a1*v*v
#define muc 0.5
#define mue 0.8
#define fN 9.8
#define k 1.0
#define m 1.0
#define Damping 0 //Choose the type of damping
#define om 3
#define mu 0.5
using namespace std;
//-------------------
//Global variables
double omega2 = k/m;
double gb1= b1/m;
double ga1= a1/m;
double mu = 0.5;
//-------------------
//Functions
void runge4(double, double* , double, double);
double f(double, double*, double, int);
double Damp(double*, double);
double mu = (double *);
//--------------------------------------
main(){
//Declaration of variables;
double t=0.0, y[N], a;
double yant, yact;
double Et, Ec, Ep;
//Save data in Runge4.dat
FILE *output;
output= fopen("Runge4.dat","w");
y[0]= 1.0;// initial position
y[1]= 0.0;// initial velocity
//Damping .......
a = Damp(y, t);
fprintf(output, "%f\t%f\t%f\t%f\n", t, y[0], y[1], a);
for (t= MIN; t <= MAX ; t += dist){
yant = y[1];
runge4(t, y, dist, a);
yact = y[1];
//Damping......
a = Damp(y,t);
fprintf(output, "%f\t%f\t%f\t%f\n", t, y[0], y[1], a);
}
printf("data stored in Runge4.dat\n");
fclose(output);
} //End of main program
//------------------------------------------------------
//Runge-Kutta function
void runge4(double t, double y[], double step, double a) { // rk subroutine
double f(double t, double y[], double a, int i);
double Dt = step/2.0, // the midpoint
yt1[N], yt2[N], yt3[N], k1[N], k2[N], k3[N],k4[N]; // for Runge-Kutta
int i;
for (i = 0; i<N; i++){
k1[i] = f(t, y, a, i);
yt1[i]= y[i]+0.5*(k1[i]*step);
}
for (i = 0; i<N; i++){
//Damping.....
a = Damp(yt1,t);
k2[i] = f(t+Dt, yt1, a, i);
yt2[i]= y[i]+0.5*(k2[i]*step);
}
for (i = 0; i<N; i++){
//Damping.....
a = Damp(yt2,t);
k3[i] = f(t+Dt, yt2, a, i);
yt3[i]= y[i]+(k3[i]*step);
}
for (i = 0; i<N; i++){
//Damping....
a = Damp(yt3,t);
k4[i]= f(t + step, yt3, a, i);
}
for (i = 0; i<N; i++)
y[i] += (k1[i]+2*k2[i]+2*k3[i]+k4[i])*step/6.0; //Runge-Kutta 4th order
}
//---------------------------------------------
double f(double t, double y[], double a, int i) {// RHS function
if (i == 0) return(y[1]); // RHS of first equation
if (i == 1) return(a); // RHS of second equation
}
//---------------------------------------------
//Damping functions
double Damp(double yf[],double t){
double res;
//F=0
if(Damping == 0)
res= -mu*yf[1]*(yf[0]*yf[0] - 1);
//F=-bv
else if(Damping == 1)
res= -omega2*yf[0]-gb1*yf[1];
//F=-b*v*v
else if(Damping == 2){
if(yf[1] >= 0.0)
res= -omega2*yf[0]-ga1*yf[1]*yf[1];
else
res= -omega2*yf[0]+ga1*yf[1]*yf[1];
}
//F = -muc*N
else if(Damping == 3){
if(yf[1] >= 0.0)
res= -omega2*yf[0]-muc*fN;
else
res= -omega2*yf[0]+muc*fN;}
else{
cout << "Unknown damping" << endl;
return -1;}
return res;
}
Muchas gracias
Más información sobre la lista de distribución Cconclase