Dev - C++ - No encuentro el error en el codigo

 
Vista:

No encuentro el error en el codigo

Publicado por Jonathan Jumper (1 intervención) el 28/04/2017 05:59:04
//El codigo me lo paso un amigo para una tarea pero cuando lo compile me da error y mi amigo no contesta
//mis mensajes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
//Descripcion
//x0 condicion inicial
//xf punto final
//y0 condicion inicial
//h tama¤o de paso
//Los metodos implementados resuelven ecuaciones del tipo
// dy/dx = f(x,y).
//Estos metodos usan un intervalo de paso igual a h, en el intervalo (x0,xf).
//La funcion a resolver es definida como f(x,y).
//Tambien se realizo Runge-Kutta para un sistema de ecuaciones rk42()
//este metodo usa un intervalo de paso igual a h, las condiciones
//iniciales son x0,y0,z0. Las funciones a evaluar son: f(x,y,z) y
//g(x,y,z)
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <dos.h>
using namespace std;
//Funcion a evaluar f(x,y)
float f(float x,float y)
{
  return 8*exp(1.5*(x))-7*(y);
}
//Funciones a evaluar f(x,y,z)
float f(float x,float y,float z)
{
  return (x)+(y)-(z)*(z);
}
//g(x,y,z)
float g(float x,float y,float z)
{
  return (x)*(x)-(z)+(y)*(y);
}
 
 
	void Euler(float x0,float xf,float y0,float h)
	{
	  float x=x0,y=y0;
	  clrscr();
	  gotoxy(32,2);
	  cout<<" METODO DE EULER ";
	  gotoxy(10,4);
	  cout<<"Xo = "<<setw(10)<<setprecision(5)<<x0;
	  gotoxy(10,5);
	  cout<<"Xf = "<<setw(10)<<setprecision(5)<<xf;
	  gotoxy(10,6);
	  cout<<"Yo = "<<setw(10)<<setprecision(5)<<y0;
	  gotoxy(10,7);
	  cout<<"h  = "<<setw(10)<<setprecision(5)<<h;
	  gotoxy(10,9);
	  cout<<" x                y";
	  gotoxy(9,10);
	  cout<<"----------------------";
	  cout<<endl;
	  cout<<setw(10) <<setprecision(5) << setiosflags(ios::fixed) << x;
	  cout<<setw(20) <<setprecision(5) << setiosflags(ios::fixed) << y << endl;
	  while(x<xf){
		y+=h*f(x,y);
		x+=h;
		cout<<setw(10) <<setprecision(5) << setiosflags(ios::fixed) << x
			<<setw(20) <<setprecision(5) << setiosflags(ios::fixed) << y << endl;
	  }
   }
	  void Heun(float x0,float xf,float y0,float h)
	{
	  float x=x0,y=y0;
	  float k1,k2;
	  clrscr();
	  gotoxy(32,2);
	  cout<<"METODO DE HEUN (RK Orden 2)"<<endl;
	  gotoxy(10,4);
	  cout<<"Xo = "<< setw(10) << setprecision(5) <<x0;
	  gotoxy(10,5);
	  cout<<"Xf = "<< setw(10) << setprecision(5) <<xf;
	  gotoxy(10,6);
	  cout<<"Yo = "<< setw(10) << setprecision(5) <<y0;
	  gotoxy(10,7);
	  cout<<"h  = "<< setw(10) << setprecision(5) <<h;
	  gotoxy(10,9);
	  cout<<"x                y";
	  gotoxy(9,10);
	  cout<<"----------------------";
	  cout<<endl;
	  cout<<setw(10) << setprecision(5) << setiosflags(ios::fixed) << x;
	  cout<<setw(20) << setprecision(5) << setiosflags(ios::fixed) << y <<endl;
	  while(x<xf){
		k1=h*f(x,y);
		k2=h*f(x+h,y+k1);
		y+=(k1/2.0+k2/2.0);
		x+=h;
		cout<<setw(10) << setprecision(5) << setiosflags(ios::fixed) << x
			<<setw(20) << setprecision(5) << setiosflags(ios::fixed) << y <<endl;
	  }
   }
 
	   void rk4(float x0,float xf,float y0,float h)
	{
	   float x=x0,y=y0;
	   float k1,k2,k3,k4;
	   clrscr();
	   gotoxy(32,2);
	   cout<<"METODO DE RUNGE KUTTA (ORDEN 4)";
	   gotoxy(10,4);
	   cout<<"Xo = "<<setw(10)<<setprecision(5)<<x0;
	   gotoxy(10,5);
	   cout<<"Xf = "<<setw(10)<<setprecision(5)<<xf;
	   gotoxy(10,6);
	   cout<<"Yo = "<<setw(10)<<setprecision(5)<<y0;
	   gotoxy(10,7);
	   cout<<"h  = "<<setw(10)<<setprecision(5)<<h;
	   gotoxy(10,9);
	   cout<<"x                y";
	   gotoxy(9,10);
	   cout<<"----------------------";
	   cout<<endl;
	   cout<<setw(10) << setprecision(5) << setiosflags(ios::fixed) << x;
	   cout<<setw(20) << setprecision(5) << setiosflags(ios::fixed) << y <<endl;
	   while(x<=xf)
	   {
 
		k1=h*f(x,y);
		k2=h*f(x+h/2.0,y+k1/2.0);
		k3=h*f(x+h/2.0,y+k2/2.0);
		k4=h*f(x+h,y+k3);
		y+=(k1+2*k2+2*k3+k4)/6.0;
		x+=h;
		cout<<setw(10) << setprecision(5) << setiosflags(ios::fixed) << x;
		cout<<setw(20) << setprecision(5) << setiosflags(ios::fixed) << y;
	   }
	}
 
 
	  void rk5(float x0,float xf,float y0,float h)
	{
	   float x=x0,y=y0;
	   float k1,k2,k3,k4,k5,k6;
	   clrscr();
	   gotoxy(32,2);
	   cout<<"METODO DE RUNGE KUTTA (ORDEN 5)";
	   gotoxy(10,4);
	   cout<<"Xo = "<<setw(10)<<setprecision(5)<<x0;
	   gotoxy(10,5);
	   cout<<"Xf = "<<setw(10)<<setprecision(5)<<xf;
	   gotoxy(10,6);
	   cout<<"Yo = "<<setw(10)<<setprecision(5)<<y0;
	   gotoxy(10,7);
	   cout<<"h  = "<<setw(10)<<setprecision(5)<<h;
	   gotoxy(10,9);
	   cout<<"x                y";
	   gotoxy(9,10);
	   cout<<"----------------------";
	   cout<<endl;
	   cout<<setw(10) << setprecision(5) << setiosflags(ios::fixed) << x;
	   cout<<setw(20) << setprecision(5) << setiosflags(ios::fixed) << y <<endl;
	   while(x<=xf)
	   {
 
		k1=h*f(x,y);
		k2=h*f(x+h/4.0,y+k1/4.0);
		k3=h*f(x+h/4.0,y+k1/8.0+k2/8.0);
		k4=h*f(x+h/2.0,y-k2/2.0+k3);
		k5=h*f(x+3*h/4.0,y+3*k1/16.0+9*k4/16.0);
		k6=h*f(x+h,y-3*k1/7.0+2*k2/7.0+12*k3/7.0-12*k4/7.0+8*k5/7.0);
		y+=(7*k1+32*k3+12*k4+32*k5+7*k6)/90.0;
		x+=h;
		cout<<setw(10)<<setprecision(5)<<setiosflags(ios::fixed)<<x;
		cout<<setw(20)<<setprecision(5)<<setiosflags(ios::fixed)<<y<<endl;
	   }
	}
 
 
	 void rkf(float x0,float xf,float y0,float h)
	 {
	   float k1,k2,k3,k4,k5,k6;
	   float x=x0,y=y0;
	   float r=0;
	   clrscr();
	   gotoxy(28,2);
	   cout<<" METODO DE RUNGE-KUTTA-FEHLDBERG ";
	   gotoxy(10,4);
	   cout<<"Xo = "<<setw(10)<<setprecision(5)<<x0;
	   gotoxy(10,5);
	   cout<<"Xf = "<<setw(10)<<setprecision(5)<<xf;
	   gotoxy(10,6);
	   cout<<"Yo = "<<setw(10)<<setprecision(5)<<y0;
	   gotoxy(10,7);
	   cout<<"h  = "<<setw(10)<<setprecision(5)<<h;
	   gotoxy(10,9);
	   cout<<"x                y        error";
	   gotoxy(8,10);
	   cout<<"---------------------------------";
	   cout<<endl;
	   cout<< setw(10) << setprecision(5) << setiosflags(ios::fixed) << x;
	   cout<< setw(20) << setprecision(5) << setiosflags(ios::fixed) << y;
	   cout<< setw(10) << setprecision(5) << setiosflags(ios::fixed) << r << endl;
	   while(x<=xf){
		k1=h*f(x,y);
		k2=h*f(x+h/4.0,y+k1/4.0);
		k3=h*f(x+3*h/8.0,y+3*k1/32.0+9*k2/32.0);
		k4=h*f(x+12*h/13.0,y+1932*k1/2197.0-7200*k2/2197.0+7296*k3/2197.0);
		k5=h*f(x+h,y+439*k1/216.0-8*k2+3680*k3/513.0-845.0*k4/4104.0);
		k6=h*f(x+h/2.0,y-8*k1/27.0+2*k2-3544*k3/2565.0+1859*k4/4104.0-11*k5/40.0);
		r=fabs(k1/360.0+128*k3/4275.0+197*k4/75240.0+k5/50.0+2*k6/55.0)/h;
		y+=25*k1/216.0+1408*k3/2565.0+2197*k4/4104.0-k5/5.0;
		x+=h;
		cout<<setw(10)<<setprecision(5) << setiosflags(ios::fixed) << x;
		cout<<setw(20)<<setprecision(5) << setiosflags(ios::fixed) << y;
		cout<<setw(10)<<setprecision(5) << setiosflags(ios::fixed) << r << endl;
	   }
	}
 
	void rk42(float x0,float y0,float z0,float xf,float h)
	{
	  float x=x0,y=y0,z=z0;
	  float k1,k2,k3,k4;
	  float m1,m2,m3,m4;
	  gotoxy(25,2);
	  cout<<" RUNGE-KUTTA-4 PARA UN SISTEMA DE ECUACIONES ";
	  gotoxy(9,4);
	  cout<<" x         y         z";
	  gotoxy(7,5);
	  cout<<"------------------------";
	  cout<<endl;
	  cout<<setw(10)<<setprecision(5)<<setiosflags(ios::fixed)<<x;
	  cout<<setw(10)<<setprecision(5)<<setiosflags(ios::fixed)<<y;
	  cout<<setw(10)<<setprecision(5)<<setiosflags(ios::fixed)<<z<<endl;
	   while(x<=xf){
	   k1=h*f(x,y,z);
	   m1=h*g(x,y,z);
 
	   k2=h*f(x+h/2.0,y+k1/2.0,z+m1/2.0);
	   m2=h*g(x+h/2.0,y+k1/2.0,z+m1/2.0);
 
	   k3=h*f(x+h/2.0,y+k2/2.0,z+m2/2.0);
	   m3=h*g(x+h/2.0,y+k2/2.0,z+m2/2.0);
 
	   k4=h*f(x+h,y+k3,z+m3);
	   m4=h*g(x+h,y*k3,z+m3);
 
	   y+=(k1+2*k2+2*k3+k4)/6.0;
	   z+=(m1+2*m2+2*m3+m4)/6.0;
	   x+=h;
	   cout<<setw(10)<<setprecision(5)<<setiosflags(ios::fixed)<<x;
	   cout<<setw(10)<<setprecision(5)<<setiosflags(ios::fixed)<<y;
	   cout<<setw(10)<<setprecision(5)<<setiosflags(ios::fixed)<<z<<endl;
	  }
	}
 
	int Menu(char *titulo,char *opciones[])
	{
	int op,i;
	clrscr();
	i=0;
	gotoxy(34,4);
	cout<<titulo<<endl; cout<<endl;
	for(;*opciones[i];i++)
	cout<<"\t\t\t\t " << i+1 << ".- " << opciones[i] << endl;
	cout<<"\t\t\t\t " << i+1 << ".- Salir " << endl;
	cout<<endl;
	cout<<"\t\t\t\t Opcion-> ";
	cin>>op;
	return op;
   }
	  void Lee(float &x0,float &xf,float &y0,float &h)
	  {
		gotoxy(34,16);
		cout<<"Xo = "; cin>>x0;
		gotoxy(34,17);
		cout<<"Xf = "; cin>>xf;
		gotoxy(34,18);
		cout<<"Yo = "; cin>>y0;
		gotoxy(34,19);
		cout<<"Tama¤o del paso h = ";
		cin>>h;
	  }
 
 
   int main(void)
   {
	 float x0,y0,xf,h;
	 int op;
	 enum{EULER=1,HEUN,RK4,RK5,RKF,RK42,SALIR};
	 char *Opciones[]={
						"Euler",
						"Heun. Runge-Kutta 2o. Orden",
						"Runge-Kutta 4o. Orden",
						"Runge-Kutta 5o. Orden",
						"Runge-Kutta-Fehldberg",
						"Runge-Kutta Para un Sistema de Ecuaciones",
						""
					   };
 
	 do{
	   op=Menu("ECUACIONES DIFERENCIALES",Opciones);
	   switch(op){
		 case EULER: Lee(x0,xf,y0,h);
					 Euler(x0,xf,y0,h);
					 getch();
					 break;
		 case HEUN:  Lee(x0,xf,y0,h);
					 Heun(x0,xf,y0,h);
					 getch();
					 break;
		 case RK4:   Lee(x0,xf,y0,h);
					 rk4(x0,xf,y0,h);
					 getch();
					 break;
		 case RK5:   Lee(x0,xf,y0,h);
					 rk5(x0,xf,y0,h);
					 getch();
					 break;
		 case RKF:   Lee(x0,xf,y0,h);
					 rkf(x0,xf,y0,h);
					 getch();
					 break;
		 case RK42:  clrscr();
					 rk42(0,1,1,0.1,0.01);
					 getch();
					 break;
 
		 case SALIR: gotoxy(34,20);
					 cout<<"Fin de "<<__FILE__;
					 gotoxy(34,21);
					 cout<<"Espere un momento...";
					 sleep(1);
					 exit(0);
					 break;
		 default:    gotoxy(34,15);
					 cout<<"Opcion no permitida";
					 getch();
					 break;
		}
	 }while(op!=SALIR);
	 return 0;
   }
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 45
Ha disminuido su posición en 6 puestos en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

No encuentro el error en el codigo

Publicado por xve (68 intervenciones) el 28/04/2017 10:35:55
Pero... que error te da?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar