Está en la página 1de 39

1.

#include <iostream>
2. #include <stdio.h>
3. #include <windows.h>
4. #include <stdlib.h>
5. #include <math.h>
6. int c,f,respg=2;
7. float mataux[50][50];
8.
9. using namespace std;
10. //solucion raices
11. double funcion(double x){
12. return(x*x+x-4);
13. }
14.
15. int Biseccion()
16. {
17. float a, b, ep,xm,e;
18. int i=0;
19. do{
20. cout<<"Teclear error permisible"<<endl;
21. cin>>ep;
22. } while(ep <= 0 || ep >= 1);
23.
24. do{
25. cout<<"Teclear valor de x1:"<<endl;
26. cin>>a;
27. cout<<"Teclear valor de x2:"<<endl;
28. cin>>b;
29. }while (funcion(a)*funcion(b)>=0);
30.
31. printf(" I X1 X2 X2-
X1 Xm f(x1) f(xm)\n\n");
32.
33. do{
34. e=b-a;
35. if(e<0)
36. e=-1*e;
37. i++;
38. xm=(a+b)/2;
39. printf("%10i%10.4f%10.4f%10.4f%10.4f%10.4f%10.4f",i,a,b
,(b-a),xm,funcion(a),funcion(xm));
40. printf("\n");
41.
42. if(funcion(xm)==0)
43. break;
44. else
45. if(funcion(a)*funcion(xm)<0)
46. b=xm;
47.
48. else
49. a=xm;
50.
51. } while (e>ep && i<50);
52.
53. cout<<"\nla raiz es:"<<xm<<endl;
54. system ("PAUSE");
55. return 0;
56. }
57.
58. int Fpos()
59. {
60. float x1,xi,xii,ep,e;
61. int i=1,c=0,ite=0;
62. do{
63. cout<<"teclear el error permisible:"<<endl;
64. cin>>ep;
65. }
66. while(ep<=0 || ep>=1);
67. do{
68. cout<<"teclear el valor de x1:"<<endl;
69. cin>>x1;
70. cout<<"teclear valor de x2:"<<endl;
71. cin>>xi;
72. }
73. while (funcion(x1)*funcion(xi)>=0);
74. printf(" I Xi f(xi) Xi-
X1 f(xi)-f(x1) xi+1 e f(xi+1)\n\n");
75. do{
76. if(c==0){
77. printf("%10i%10.4f%10.4f%10.4f%10.4f - -
-",i,x1,funcion(x1),x1-x1,funcion(x1)-funcion(x1));
78. printf("\n");
79. c++;}
80.
81. if (c>0){
82. xii=xi-((funcion(xi)*(xi-x1))/(funcion(xi)-funcion(x1)));
83. e=xii-xi;
84. if (e<0)
85. e= -1*e;
86. printf("%10i%10.4f%10.4f%10.4f%10.4f%10.4f%8.4f%9.4f"
,i,xi,funcion(xi),(xi-x1),funcion(xi)-
funcion(x1),xii,e,funcion(xii));
87. printf("\n");
88. xi=xii;
89. if(funcion(xii)==0)
90. break;
91.
92. }
93. i++;
94. ite++;
95. }while ((e>ep) && ite<50);
96. if(ite<50)
97. cout<<"la raiz es:"<<xii<<endl;
98. else (ite>=50);
99. cout<<"no existe solucion"<<endl;
100. system("PAUSE");
101. return 0;
102. }
103.
104. int Secante()
105. {
106. double xi,xi1,xi2,e,ep;
107. int i=1;
108. do{
109. cout<<"teclear error permisible"<<endl;
110. cin>>ep;
111. }
112. while(ep<=0 || ep>=1);
113. do
114. {
115. cout<<"Teclea el valor de x1: "<<endl;
116. cin>>xi;
117. cout<<"Teclea el valor de x2: "<<endl;
118. cin>>xi1;
119. }while(funcion(xi1)-funcion(xi)==0);
120.
121. printf(" I Xi xi+1 f(xi) f
(xi+1) xi+2 e f(xi+2)\n\n");
122. do{
123. xi2=xi1-((funcion(xi1)*(xi1-xi)))/(funcion(xi1)-
funcion(xi));
124. e=xi2-xi1;
125. if(e<0)
126. e=-1*e;
127. printf("%10i%10.4f%10.4f%10.4f%10.4f%10.4f%8.4f%9.4f"
,i,xi,xi1,funcion(xi),funcion(xi1),xi2,e,funcion(xi2));
128. printf("\n");
129. xi=xi1;
130. xi1=xi2;
131. }
132. while (e>ep);
133.
134. if(i<60){
135. cout<<"la raiz es:"<<xi2<<endl;
136. }
137. else
138. cout<<"el metodo diverge"<<endl;
139. system ("pause");
140.
141. }
142. double deriv(double d){
143. return(6*d);
144. }
145.
146. int Newton_Raphson()
147. {
148. float xi,xii,e,ep;
149. int i=1;
150. do{
151. cout<<"teclear error permisible"<<endl;
152. cin>>ep;
153. }
154. while(ep<=0 || ep>=1);
155. do{
156. cout<<"teclear valor de x1:"<<endl;
157. cin>>xi;
158. }
159. while (deriv(xi)==0);
160. printf(" I Xi f(xi) f'(xi)
xi+1 e\n\n");
161.
162. do{
163. xii=xi-(funcion(xi))/(deriv(xi));
164. if (deriv(xi)==0){
165. cout<<"EL METODO DIVERGE"<<endl;
166. break;
167. }
168. e=xii-xi;
169. if(e<0)
170. e=-1*e;
171. printf("%10i%10.4f%10.4f%10.4f%10.4f%10.4f",i,xi,funcion(xi
),deriv(xi),xii,e);
172. printf("\n");
173. xi=xii;
174. if(funcion(xii)==0)
175. break;
176. i++;
177. }
178. while (e>=ep && i<60);
179. if (i<60){
180. if(deriv(xi)!=0){
181. cout<<"la raiz es:"<<xii<<endl;
182. }
183. }
184. if (i>=60){
185. cout<<"el metodo no converge dentro de este numero de
interaiones"<<endl;
186. }
187. system ("PAUSE");
188. return 0;
189. }
190.
191. double func(double x){
192. return(3*x*x-5);
193. }
194.
195. double dosdev(double v){
196. return(6);
197. }
198.
199. int Newton_2do_Orden()
200. {
201. double xi,xi1,e,ep;
202. int i=1;
203. do{
204. cout<<"teclear error permisible:"<<endl;
205. cin>>ep;
206. }
207. while(ep<=0 || ep>=1);
208. cout<<"teclear el valor de x1:"<<endl;
209. cin>>xi;
210. printf(" I Xi f(xi) f'(xi) f
''(xi) xi+1 f(xi+1) e\n\n");
211. do{
212. xi1=xi-(func(xi)/(deriv(xi)-
(func(xi)*dosdev(xi))/(2*deriv(xi))));
213. e=xi1-xi;
214. if (e<0)
215. e=-1*e;
216. printf("%10i%10.4f%10.4f%10.4f%10.4f%10.4f%8.4f%9.4f",i,
xi,func(xi),deriv(xi),dosdev(xi),xi1,func(xi1),e);
217. printf("\n");
218. xi=xi1;
219. if(func(xi1)==0)
220. break;
221. i++;
222. }
223. while(e>=ep && i<60);
224. if (i<60){
225. cout<<"la raiz es :"<<xi1<<endl;
226. }else
227. cout<<"el metodo no converge"<<endl;
228. system ("pause");
229. return 0;
230. }
231.
232. //solucion ecuaciones lineales
233. int Gauss()
234. {
235. int i,j,p=0,k,s,r,q;
236. float mat[50][50],aux,x[50],suma;
237. if(respg==2){
238. do{
239. cout<<"teclear el numero de ecuaciones:"<<endl;
240. cin>>f;
241. cout<<"teclear numero de incognitas:"<<endl;
242. cin>>c;
243. if (c!=f){
244. system ("CLS");
245. cout<<"el numero de ecuaciones debe ser igual al
numero de incognitas\n"<<endl;
246. }
247. }while(c!=f);
248. for (i=0;i<f;i++){
249. for (j=0;j<c+1;j++){
250. if (j==0){
251. cout<<"introducir datos de la
matriz"<<endl;
252. }
253. cout<<"a["<<i<<"]"<<"["<<j<<"]:";
254. cin>>mat[i][j];
255. }
256. }
257. for(i=0;i<f;i++){
258. cout<<endl;
259. for(j=0;j<c+1;j++){
260. mataux[i][j]=mat[i][j];
261. }
262. }
263. }
264. if(respg==1){
265. for(i=0;i<f;i++){
266. cout<<endl;
267. for(j=0;j<c+1;j++){
268. mat[i][j]=mataux[i][j];
269. }
270. }
271. }
272. cout<<"\nMatriz inicial\n\n"<<endl;
273. for (i=0;i<f;i++){
274. printf ("\n");
275. for (j=0;j<c+1;j++){
276. printf ("%10.4f",mat[i][j]);
277. }
278. }
279. for (i=0;i<f;i++){
280. aux=mat[p][p];
281. if (aux!=0){
282. for (k=i+1;k<f;k++){
283. aux=mat[k][p];
284. for (j=0;j<c+1;j++){
285. mat[k][j]=(aux/mat[p][p])*(mat[p][j])-mat[k][j];
286. }
287. }
288. }
289. if (aux==0){
290. i=f+1;
291. }
292. p=p+1;
293. }
294. x[f-1]=mat[f-1][c]/mat[f-1][c-1];
295. for (i=f-2;i>=0;i--){
296. suma=0;
297. for(j=i+1;j<=f-1;j++){
298. suma=suma+mat[i][j]*x[j];
299. x[i]=(mat[i][c]-suma)/mat[i][i];
300. }
301. }
302. if (aux!=0){
303. printf ("\n\n\n");
304. cout<<"Matriz resultante"<<endl;;
305. for (i=0;i<f;i++){
306. printf ("\n");
307. for (j=0;j<c+1;j++){
308. printf ("%10.4f",mat[i][j]);
309. }
310. }
311. printf ("\n\n\n");
312. for (i=0;i<c;i++){
313. printf("\nX%i= %f",i+1,x[i]);
314. }
315. }
316. if (aux==0){
317. cout<<"\n\nla solucion de la matriz es:"<<endl;
318. }
319. system("pause");
320. return 0;
321. }
322.
323. int Gauss_Jordan()
324. {
325. int i,j,p=0,k,s,r,q;
326. float mat[50][50],aux;
327. if(respg==2){
328. do
329. {
330. cout<<"teclear el numero de ecuaciones:"<<endl;
331. cin>>f;
332. cout<<"teclear numero de incognitas:"<<endl;
333. cin>>c;
334.
335.
336.
337.
338. }while(c!=f);
339.
340. for (i=0;i<f;i++){
341. for (j=0;j<c+1;j++){
342. if (j==0){
343. cout<<"introducir los datos de la matriz"<<endl;
344. }
345. cout<<"a["<<i<<"]"<<"["<<j<<"]:";
346. cin>>mat[i][j];
347. }
348. }
349. for(i=0;i<f;i++){
350. cout<<endl;
351. for(j=0;j<c+1;j++){
352. mataux[i][j]=mat[i][j];
353. }
354. }
355. }
356. if(respg==1){
357. for(i=0;i<f;i++){
358. cout<<endl;
359. for(j=0;j<c+1;j++){
360. mat[i][j]=mataux[i][j];
361. }
362. }
363. }
364.
365. cout<<"Matriz inicial\n\n"<<endl;
366. for (i=0;i<f;i++){
367. printf ("\n");
368. for (j=0;j<c+1;j++){
369. printf ("%10.4f",mat[i][j]);
370. }
371. }
372. for (i=0;i<f;i++){
373. aux=mat[p][p];
374. if (aux!=0){
375. for (s=0;s<c+1;s++){
376. mat[p][s]=(mat[p][s])*(1/aux);
377. }
378. if (i<f-1){
379. for (k=i+1;k<f;k++)
380. {
381. aux=mat[k][p];
382. for (j=0;j<c+1;j++){
383. mat[k][j]=(-aux)*(mat[p][j])+mat[k][j];
384. }
385.
386. }
387. }
388. if (i>0){
389. for (k=i-1;k>=0;k--){
390. aux=mat[k][p];
391. for (j=0;j<c+1;j++){
392. mat[k][j]=(-aux)*(mat[p][j])+mat[k][j];
393. }
394. }
395. }
396. p=p+1;
397. }
398. if (aux==0){
399. i=f+1;
400. }
401. }
402. if (aux!=0){
403. printf ("\n\n\n");
404. cout<<"la matriz resultante es la siguiente:"<<endl;
405. for (i=0;i<f;i++){
406. printf ("\n");
407. for (j=0;j<c+1;j++){
408. printf ("%10.4f",mat[i][j]);
409. }
410. }
411. printf ("\n\n\n");
412. for (i=0;i<c;i++){
413. printf("\nX%i= %f",i+1,mat[i][c]);
414. }
415. }
416. if (aux==0){
417. printf ("\n\n");
418. cout<<"la solucion de la matriz se
indetermina"<<endl;
419. }
420. system("pause");
421. return 0;
422. }
423.
424. int Montante()
425. {
426. int i,j,p=0,k,s,r,q;
427. float mat[50][50],aux,x[50], aux2;
428. if(respg==2){
429. do
430. {
431. cout<<"\ncual es el numero de ecuaciones:
"<<endl;
432. cin>>f;
433. cout<<"\nCual es el numero de incognitas:
"<<endl;
434. cin>>c;
435.
436. }while(c!=f);
437.
438. for (i=0;i<f;i++)
439. {
440. if(i==0)
441. cout<<"introducir datos de la matriz:"<<endl;
442. for (j=0;j<c+1;j++)
443. {
444. if (j<=c)
445. {
446. printf("\na[%i][%i]: ",i+1,j+1);
447. scanf("%f",&mat[i][j]);
448. }
449. }
450. }
451. for(i=0;i<f;i++){
452. cout<<endl;
453. for(j=0;j<c+1;j++){
454. mataux[i][j]=mat[i][j];
455. }
456. }
457. }
458. if(respg==1){
459. for(i=0;i<f;i++){
460. cout<<endl;
461. for(j=0;j<c+1;j++){
462. mat[i][j]=mataux[i][j];
463. }
464. }
465. }
466.
467. printf ("\nMatriz inicial:\n\n");
468. for (i=0;i<f;i++)
469. {
470. printf ("\n");
471. for (j=0;j<c+1;j++)
472. printf ("\t%f",mat[i][j]);
473. }
474.
475. for (i=0;i<f;i++)
476. {
477. aux=1;
478. aux2=mat[p-1][p-1];
479. if (aux!=0)
480. {
481. for(j=0;j<f;j++)
482. {
483. if (j!=p)
484. for (k=c;k>=0;k--)
485. {
486. if (p==0)
487. mat[j][k]=mat
[p][p]*mat[j][k]-mat[j][p]*mat[p][k];
488.
489. if(p>0)
490. mat[j][k]=(ma
t[p][p]*mat[j][k]-mat[j][p]*mat[p][k])/aux2;
491. }
492. }
493. p=p+1;
494. }
495.
496. if (aux==0)
497. i=f+1;
498. }
499.
500. for (i=0;i<c;i++)
501. x[i]=mat[i][c]/mat[i][i];
502.
503. if (aux!=0)
504. {
505. cout<<endl;
506. cout<<"Matriz resultante:"<<endl;
507. for (i=0;i<f;i++)
508. {
509. printf ("\n");
510. for (j=0;j<c+1;j++)
511. printf ("\t%f",mat[i][j]);
512. }
513.
514. printf ("\n\n\n");
515. for (i=0;i<c;i++)
516. printf("\nX%i= %f",i+1,x[i]);
517. }
518.
519. if (aux==0)
520. {
521. cout<<endl;
522. cout<<"solucion indeterminada"<<endl;
523. }
524.
525. system ("pause");
526. return 0;
527. }
528.
529. int Cramer()
530. {
531. int i,j,p=0,s,r,q,k,l,m;
532. float
mat[50][50],aux,b[50],copia[50][50],det,x[50],detx[50],detaux;
533. if(respg==2){
534. do
535. {
536. cout<<"\nnumero de ecuaciones del sistema:
"<<endl;
537. cin>>f;
538. cout<<"\nnumero de incognitas: "<<endl;
539. cin>>c;
540.
541. }while(c!=f);
542.
543. for (i=1;i<=f;i++)
544. {
545. if(i==1)
546. cout<<"\n******* introducir datos de matriz
inicial: ********"<<endl;
547. for (j=1;j<c+2;j++)
548. {
549. if (j<=c){
550. printf("\na[%i][%i]: ",i,j);
551. scanf("%f",&mat[i][j]);
552. }
553. if (j>c){
554. printf("\na[%i][%i]: ",i,j);
555. scanf("%f",&b[i]);
556. }
557.
558. }
559. }
560. for(i=0;i<f;i++){
561. for(j=0;j<c+1;j++){
562. mataux[i][j]=mat[i+1][j+1];
563. if(j==c){
564. mataux[i][j]=b[i+1];
565. }
566. }
567. }
568. }
569. if(respg==1){
570. for(i=0;i<f;i++){
571. for(j=0;j<c;j++){
572. mat[i+1][j+1]=mataux[i][j];
573. }
574. }
575. for(i=0;i<c;i++){
576. b[i+1]=mataux[i][c];
577. }
578. }
579.
580. for (i=1;i<=c;i++){
581. for (j=1;j<=c;j++){
582. copia[i][j]=mat[i][j];
583. }
584. }
585. printf ("\n\nMatriz Inicial\n\n");
586. for (i=1;i<=c;i++){
587. printf("\n");
588. for (j=1;j<=c+1;j++){
589. if (j<=c){
590. printf("%7.2f",copia[i][j]);
591. }
592. if (j==c+1){
593. printf("%7.2f",b[i]);
594. }
595. }
596. }
597. m=c-1;
598. det=mat[1][1];
599. for(k=1;k<=m;k++)
600. { l=k+1;
601. for(p=l;p<=c;p++)
602. { for(s=l;s<=c;s++)
603. mat[p][s] = ( mat[k][k]*mat[p][s]-
mat[k][s]*mat[p][k] )/mat[k][k]; }
604. det=det*mat[k+1][k+1];
605. }
606. detaux=det;
607. if (det==0){
608. cout<<"no existe solucion";
609. }
610. if (det!=0){
611. for (i=1;i<=c;i++){
612. for (j=1;j<=c;j++){
613. mat[i][j]=copia[i][j];
614. }
615. }
616. for (j=1;j<=c;j++){
617. for (i=1;i<=c;i++){
618. copia[i][j]=b[i];
619. }
620. m=c-1;
621. det=copia[1][1];
622. for(k=1;k<=m;k++)
623. { l=k+1;
624. for(p=l;p<=c;p++)
625. { for(s=l;s<=c;s++)
626. copia[p][s] = ( copia[k][k]*copia[p][s]-
copia[k][s]*copia[p][k] )/copia[k][k]; }
627. det=det*copia[k+1][k+1];
628. }
629. detx[j]=det;
630. for (q=1;q<=c;q++){
631. for (r=1;r<=c;r++){
632. copia[q][r]=mat[q][r];
633. }
634. }
635. x[j]=detx[j]/detaux;
636. }
637. }
638. for (i=1;i<=c;i++){
639. printf("\nx%i= %f",i,x[i]);
640. }
641. system("pause");
642. return 0;
643. }
644.
645. int Jacobi()
646. {
647. int i,j,p=0,k,cont=0;
648. float
mat[50][50],aux,x[50],suma,ec=0,error=0,aux2[50],ep=0,sumat[50],err
ort,cont2=0;
649. if(respg==2){
650.
651. do{
652. printf("\ncuantas ecuaciones se incluyen en el sistema: ");
653. scanf("%i",&f);
654. printf("\ncuantas incognitas existen: ");
655. scanf("%i",&c);
656. if (c!=f){
657. system ("CLS");
658. printf("el numero de ecuaciones debe ser igual al
numero de incognitas\n");
659. }
660. }while(c!=f);
661. for(i=0;i<f;i++){
662. if(i==0)
663. cout<<"\n\t\tleer matriz:"<<endl;
664. for(j=0;j<c+1;j++){
665. cout<<"\na["<<i+1<<"]["<<j+1<<"]:"<
<endl;
666. cin>>mat[i][j];
667. }
668. }
669. for(i=0;i<f;i++){
670. cout<<endl;
671. for(j=0;j<c+1;j++){
672. mataux[i][j]=mat[i][j];
673. }
674. }
675. }
676. if(respg==1){
677. for(i=0;i<f;i++){
678. cout<<endl;
679. for(j=0;j<c+1;j++){
680. mat[i][j]=mataux[i][j];
681. }
682. }
683. }
684. do
685. {
686. printf("Teclea el error permisible: ");
687. scanf ("%f",&ep);
688. }while(ep<=0 || ep>=1);
689. printf ("\nMatriz inicial\n\n");
690. for (i=0;i<f;i++){
691. printf ("\n");
692. for (j=0;j<c+1;j++){
693. printf ("\t%f",mat[i][j]);
694. }
695. }
696. printf ("\n\n\n");
697. for(i=0;i<f;i++){
698. x[i]=0;
699. }
700. for(i=1;i<((f+1)*2)-1;i++){
701. if (i<f+1){
702. printf(" X%i",i);
703. }
704. if (i>=f+1){
705. printf(" X%i",i-f);
706. }
707. }
708. do{
709. if (cont2<50){
710. cont=0;
711. printf("\n");
712. for (k=0;k<f;k++){
713. printf("%8.4f",x[k]);
714. }
715. for(i=0;i<f;i++){
716. suma=0;
717. suma=suma+mat[i][c];
718. for (j=0;j<c;j++){
719. if(j!=i){
720. suma=suma-mat[i][j]*x[j];
721. }
722. }
723. sumat[i]=suma;
724. aux2[i]=x[i];
725. }
726. for (i=0;i<f;i++){
727. aux=mat[i][i];
728. if (aux==0){
729. i=f+1;
730. }
731. if(aux!=0){
732. x[i]=sumat[i]/aux;
733. printf("%8.4f",x[i]);
734. errort=x[i]-aux2[i];
735. if (errort<0){
736. errort=-1*errort;
737. }
738. if (errort<ep){
739. cont++;
740. }
741. if (cont==f){
742. error=1;
743. }
744. }
745. if (aux==0){
746. error=1;
747. }
748. }
749. }
750. if (cont2>=50){
751. error=1;
752. }
753. cont2++;
754. }while (error==0 && aux!=0);
755. if (cont2<50){
756. if (aux!=0){
757. printf ("\n\n\n");
758. for (i=0;i<c;i++){
759. printf("\nX%i= %f",i+1,x[i]);
760. }
761. }
762. }
763. if (aux==0){
764. printf ("\n\nla solucion de la matriz se
indetermina");
765. }
766. if (cont2>=50){
767. system("CLS");
768. printf("\n\n\n******el metodo no
converge*******");
769. }
770. system("pause");
771. return 0;
772. }
773.
774. int Gauss_Seidel()
775. {
776. int i,j,p=0,k,cont=0,cont2=0;
777. float
mat[50][50],aux,x[50],suma,ec=0,error=0,aux2,ep=0,errort;
778. if(respg==2){
779.
780. do
781. {
782. cout<<"\nnumero de ecuaciones del sistema: "<<endl;
783. cin>>f;
784. cout<<"\nnumero de incognitas: "<<endl;
785. cin>>c;
786.
787. }while(c!=f);
788.
789. for (i=0;i<f;i++)
790. {
791. if(i==0)
792. printf("\n******* introducir datos de la matriz:
********");
793. for (j=0;j<c+1;j++)
794. if (j<=c)
795. {
796. printf("\na[%i][%i]: ",i+1,j+1);
797. scanf("%f",&mat[i][j]);
798. }
799. }
800. for(i=0;i<f;i++){
801. cout<<endl;
802. for(j=0;j<c+1;j++){
803. mataux[i][j]=mat[i][j];
804. }
805. }
806. }
807. if(respg==1){
808. for(i=0;i<f;i++){
809. cout<<endl;
810. for(j=0;j<c+1;j++){
811. mat[i][j]=mataux[i][j];
812. }
813. }
814. }
815.
816. do
817. {
818. cout<<"\nerror permisible: "<<endl;
819. cin>>ep;
820. }while(ep<=0 || ep>=1);
821.
822. cout<<"estas es la matriz inicial:"<<endl;
823. for (i=0;i<f;i++)
824. {
825. cout<<endl;
826. for (j=0;j<c+1;j++)
827. printf ("\t%f",mat[i][j]);
828. }
829.
830. cout<<endl;
831. for(i=0;i<f;i++)
832. x[i]=0;
833.
834. for(i=1;i<((f+1)*2)-1;i++)
835. {
836. if (i<f+1)
837. printf(" X%i",i);
838.
839. if (i>=f+1)
840. printf(" X%i",i-f);
841.
842. }
843.
844. do
845. {
846. if (cont2<50)
847. {
848. cont=0;
849. cout<<endl;
850. for (k=0;k<f;k++)
851. printf("%8.4f",x[k]);
852.
853. for(i=0;i<f;i++)
854. {
855. suma=0;
856. aux=mat[i][i];
857. if (aux==0)
858. i=f+1;
859.
860. if (aux!=0)
861. {
862. suma=suma+mat[i][c];
863. for (j=0;j<c;j++)
864. if(j!=i)
865. suma=suma-
mat[i][j]*x[j];
866. aux2=x[i];
867. x[i]=suma/aux;
868. printf("%8.4f",x[i]);
869. errort=x[i]-aux2;
870. if (errort<0)
871. errort=-1*errort;
872.
873. if (errort<ep)
874. cont++;
875.
876. if (cont==f)
877. error=1;
878. }
879. }
880. }
881.
882. if (cont2>=50)
883. error=1;
884. cont2++;
885. }while (error==0 && aux!=0);
886.
887. if (cont2<50)
888. {
889. if (aux!=0)
890. {
891. cout<<endl;
892. for (i=0;i<c;i++)
893. printf("\nX%i= %f",i+1,x[i]);
894. }
895.
896. if (aux==0)
897. cout<<"solucion indeterminada"<<endl;
898. }
899.
900. if (cont2>=50)
901. {
902. system("CLS");
903. cout<<"el metodo no converge"<<endl;
904. }
905.
906. system ("pause");
907. return 0;
908. }
909.
910. //inteporlacion lineal
911. int ILNewton()
912. {float mat[200][200],difaux,x,k,y,suma=0,mult;
913. int
num,aux=0,cont=2,band=0,i,j,auxnum,aux2=0,cont2=0,auxcont,r,fac=1,a
ux3=3;
914.
915. do
916. {
917. cout<<"teclear la cantidad de puntos:"<<endl;
918. cin>>num;
919. }while (num==0);
920.
921. auxnum=num;
922. for (i=0;i<100;i++)
923. for (j=0;j<100;j++)
924. mat[i][j]=1;
925.
926. for (i=0;i<num;i++)
927. {
928. printf("\nX%i: ",i+1);
929. scanf("%f",&mat[i][0]);
930. printf("\nY%i: ",i+1);
931. scanf("%f",&mat[i][1]);
932. if (i==1)
933. difaux=mat[i][0]-mat[i-1][0];
934.
935. if (i>1)
936. {
937. if ((mat[i][0]-mat[i-1][0])!=difaux)
938. {
939. band=1;
940. i=101;
941. }
942. }
943. }
944.
945. if (band==0)
946. {
947. while(aux!=1)
948. {
949. for (i=0;i<num-1;i++)
950. {
951. mat[i][cont]=mat[i+1][cont-1]-
mat[i][cont-1];
952. if(mat[i][cont]==0)
953. aux=1;
954. }
955. num--;
956. if(mat[i][cont]!=0)
957. cont++;
958. }
959.
960. auxcont=cont;
961. for (i=0;i<auxnum;i++)
962. {
963. cout<<endl;
964. for (j=0;j<cont;j++)
965. {
966. if (aux2!=1)
967. if (j==(cont-
1) && mat[i][j]==1)
968. {
969. aux2=1;
970. cont--;
971. }
972. if (aux2!=1)
973. printf("%10.1f",mat[i][j]);
974. if (cont2>0)
975. printf("%10.1f",mat[i][j]);
976. }
977.
978. if (aux2==1)
979. {
980. cont2=1;
981. cont--;
982. }
983. }
984.
985. cout<<"\nteclear valor de x en el que desea
calcular:"<<endl;
986. cin>>x;
987. k=(x-mat[0][0])/difaux;
988. for(i=2;i<auxcont-2;i++)
989. {
990. mult=1;
991. fac=1;
992. for (j=2;j<=i;j++)
993. fac=fac*j;
994. for(r=1;r<i;r++)
995. mult=mult*(k-r);
996. suma=suma+(k*mult*mat[0][aux3])/fac;
997. aux3++;
998. }
999.
1000. y=mat[0][1]+(k*mat[0][2])+suma;
1001. printf("\ny= %f",y);
1002. }
1003.
1004. if (band==1)
1005. cout<<"el intervalo entre los puntos debe ser
igual"<<endl;
1006.
1007. system ("pause");
1008. return 0;
1009. }
1010.
1011. int Lagrange()
1012. {
1013. int i,j,n;
1014. float k, r, num, den;
1015. do
1016. {
1017. cout<<"teclear numero de puntos:"<<endl;
1018. cin>>n;
1019. }while(n<=0);
1020.
1021. float x[n-1], y[n-1];
1022. for(i=0; i<=n-1; i++)
1023. {
1024. cout<<"teclear x"<<i+1<<":"<<endl;
1025. cin>>x[i];
1026. cout<<"teclear y"<<i+1<<":"<<endl;
1027. cin>>y[i];
1028. }
1029. cout<<"teclear el valor de x:"<<endl;
1030. cin>>k;
1031.
1032. r=0;
1033. for(j=0;j<=n-1;j++)
1034. {
1035. num=1;
1036. den=1;
1037. for(i=0;i<=n-1;i++)
1038. {
1039. if(i!=j)
1040. {
1041. num=num*(k-x[i]);
1042. den=den*(x[j]-x[i]);
1043. }
1044.
1045. }
1046. r=r+num/den *y[j];
1047. }
1048.
1049. printf("\n\nx = %f \ny = %f",k, r);
1050. system ("pause");
1051. return 0;
1052.
1053. }
1054. int i,j,p=0,k,s,r,q;
1055. float matm[100][100],x[50],ao,resp=0,oo[100],aux6;
1056. float mat[100][100],sum[100],ec[100][100],a[100],b[100];
1057. int num,m,aux,aux2=2,aux3=0,aux4=1,aux5=0,aux7,hh=1;
1058. void resolver_matriz(){
1059. for (i=0;i<f;i++){
1060. aux6=matm[p][p];
1061. if (aux6!=0){
1062. for (s=0;s<c+1;s++){
1063. matm[p][s]=(matm[p][s])*(1/aux6);
1064. }
1065. if (i<f-1){
1066. for (k=i+1;k<f;k++){
1067. aux6=matm[k][p];
1068. for (j=0;j<c+1;j++){
1069. matm[k][j]=(-aux6)*(matm[p][j])+matm[k][j];
1070. }
1071. }
1072. }
1073. if (i>0){
1074. for (k=i-1;k>=0;k--){
1075. aux6=matm[k][p];
1076. for (j=0;j<c+1;j++){
1077. matm[k][j]=(-aux6)*(matm[p][j])+matm[k][j];
1078. }
1079. }
1080. }
1081. p=p+1;
1082. }
1083. if (aux6==0){
1084. i=f+1;
1085. }
1086. }
1087. if (aux6!=0){
1088. cout<<endl;
1089. cout<<"la matriz resultante es:"<<endl;
1090. for (i=0;i<f;i++){
1091. printf ("\n");
1092. for (j=0;j<c+1;j++){
1093. printf ("%10.4f",matm[i][j]);
1094. }
1095. }
1096. cout<<endl;
1097. for (i=0;i<c;i++){
1098. cout<<i+1<<matm[i][c]<<endl;
1099. }
1100. }
1101. if (aux6==0){
1102. cout<<endl;
1103. cout<<"la matriz no tiene solucion "<<endl;
1104. }
1105. }
1106.
1107.
1108. int Minimos_Cuadrados()
1109. {
1110. do {
1111. cout<<"teclear numero de puntos:"<<endl;
1112. scanf("%i",&num);
1113. }while (num==0);
1114. for (i=0;i<100;i++){
1115. for (j=0;j<100;j++){
1116. mat[i][j]=1;
1117. }
1118. }
1119. for (i=0;i<100;i++){
1120. sum[i]=0;
1121. }
1122. for (i=0;i<num;i++){
1123. printf("\nX%i: ",i+1);
1124. scanf("%f",&mat[i][0]);
1125. printf("\nY%i: ",i+1);
1126. scanf("%f",&mat[i][1]);
1127. }
1128. cout<<"introduzca el valor de m:"<<endl;
1129. cin>>m;
1130. aux=m*2;
1131. for (i=0;i<num;i++){
1132. aux2=2;
1133. for (j=2;j<=aux;j++){
1134. for (k=0;k<aux2;k++){
1135. mat[i][j]=mat[i][j]*mat[i][0];
1136. }
1137. aux2++;
1138. }
1139. }
1140. for (i=0;i<num;i++){
1141. aux3=0;
1142. for (j=aux+1;j<aux+1+m;j++){
1143. mat[i][j]=mat[i][1]*mat[i][aux3]
;
1144. if (j==aux+1){
1145. aux3++;
1146. }
1147. aux3++;
1148. }
1149. }
1150. for (j=0;j<aux+1+m;j++){
1151. for (i=0;i<num;i++){
1152. sum[j]=sum[j]+mat[i][j];
1153. }
1154. }
1155. for (i=0;i<aux+1+m;i++){
1156. if (i==0)
1157. printf(" X Y ");
1158. if (i>1 && i<m*2+1)
1159. printf(" X^%i",i);
1160. if (i>=m*2+1){
1161. printf(" X^%i
Y",hh);
1162. hh++;
1163. }
1164. }
1165. for (i=0;i<num;i++){
1166. cout<<endl;
1167. for (j=0;j<aux+1+m;j++){
1168. printf("%8.1f",mat[i][j]);
1169. }
1170. }
1171. cout<<endl;
1172. for (i=0;i<aux+1+m;i++){
1173. printf("%8.1f",sum[i]);
1174. }
1175. a[0]=num;
1176. for(i=0;i<aux+1;i++){
1177. if (i==0){
1178. a[i+1]=sum[i];
1179. }
1180. if (i>1){
1181. a[i]=sum[i];
1182. }
1183. }
1184. b[0]=sum[1];
1185. for (i=aux+1;i<=aux+m;i++){
1186. b[aux4]=sum[i];
1187. aux4++;
1188. }
1189. for(i=0;i<m+1;i++){
1190. aux5=aux5+i;
1191. for(j=0;j<m+2
;j++){
1192. ec[i][j]=a[au
x5];
1193. aux5++;
1194. if (j==m+1){
1195. e
c[i][j]=b[i];
1196. a
ux5=0;
1197. }
1198.
}
1199. }
1200. cout<<endl;
1201. for (i=0;i<m+1;i++){
1202. cout<<endl;
1203. for(j=0;j<m+2;j++){
1204. printf("%
10.1f",ec[i][j]);
1205. }
1206. }
1207. for (i=0;i<m+1;i++){
1208. for(j=0;j<m+2;j++){
1209. matm[i][j
]=ec[i][j];
1210. }
1211. }
1212. f=m+1;
1213. c=f;
1214. resolver_matriz();
1215. cout<<"telear valor de x
para el que quiere calcular y:"<<endl;
1216. cin>>ao;
1217. for (j=0;j<100;j++){
1218. oo[j]=1;
1219. }
1220. aux7=1;
1221. for (j=0;j<m;j++){
1222. for(i=0;i<aux7;i++){
1223. oo[j]=oo[j]*ao;
1224. }
1225. aux7++;
1226. }
1227. for(i=0;i<m+1;i++){
1228. if (i==0){
1229. resp=resp+matm[i][
c];
1230. }
1231. if (i>0){
1232. resp=resp+matm[i][c]*oo[i-
1];
1233. }
1234. }
1235. printf("\nY= %f",resp);
1236. system("pause");
1237. return 0;
1238. }
1239.
1240. //Derivacion E Integracion
1241. double fdos(double x)
1242. {
1243. return (3*x*x -5*x +6);
1244. }
1245.
1246. int Derivada_Por_Limites()
1247. {
1248.
1249. float x, ep, error, da, k, d, h;
1250. int n;
1251.
1252. do
1253. {
1254. cout<<"teclear el error permisible:"<<endl;
1255. cin>>ep;
1256. }while(ep<=0 || ep>=1);
1257.
1258. cout<<"teclear valor de x:"<<endl;
1259. cin>>x;
1260.
1261. k=1;
1262. h=1;
1263. n=1;
1264. da=10000000;
1265.
1266. cout<<endl;
1267. printf(" n h k
x+h f(x+h) f(x) f(x+h)-f(x) f'(x) e\n\n");
1268.
1269. do
1270. {
1271. h=h*0.1;
1272. k=k/0.1;
1273. d=(fdos(x+h)-fdos(x))*k;
1274. error=da-d;
1275. if (error < 0)
1276. error= -1*error;
1277. if(n==1)
1278. {
1279. printf("%10i%14.5f%16.4f%10.4f%10.4f%
10.4f%14.4f%10.3f -",n,h,k,(x+h),fdos(x+h),fdos(x),fdos(x+h)-
fdos(x),d);
1280. printf("\n");
1281. }
1282. else
1283. {
1284. printf("%10i%14.5f%16.4f%10.4f%10.4f%10.4f%14
.4f%10.4f%10.4f",n,h,k,(x+h),fdos(x+h),fdos(x),fdos(x+h)-
fdos(x),d,error);
1285. printf("\n");
1286. }
1287. n++;
1288. da=d;
1289.
1290. }while(error>ep && n<50);
1291.
1292. if(n>=50)
1293. cout<<"el metodo diverge"<<endl;
1294. else
1295. {
1296. cout<<endl;
1297. printf("f'(%f): %10.4f",x,d);
1298. cout<<endl;
1299. }
1300. system("pause");
1301. return 0;
1302. }
1303.
1304. int Diferencias_Finitas()
1305. {
1306. float mat[100][100],difaux,x,k,y,suma=0,mult,ao;
1307. int
num,aux=0,cont=2,band=0,i,j,auxnum,aux2=0,cont2=0,r,aux3=3,auxcont;
1308.
1309. do
1310. {
1311. printf("Numero de puntos: ");
1312. scanf("%i",&num);
1313. }while (num==0);
1314.
1315. auxnum=num;
1316. for (i=0;i<100;i++)
1317. for (j=0;j<100;j++)
1318. mat[i][j]=1;
1319.
1320. for (i=0;i<num;i++)
1321. {
1322. printf("\nX%i: ",i+1);
1323. scanf("%f",&mat[i][0]);
1324. printf("\nY%i: ",i+1);
1325. scanf("%f",&mat[i][1]);
1326. if (i==1)
1327. difaux=mat[i][0]-mat[i-1][0];
1328.
1329. if (i>1)
1330. {
1331. if ((mat[i][0]-mat[i-1][0])!=difaux)
1332. {
1333. band=1;
1334. i=101;
1335. }
1336. }
1337. }
1338.
1339. if (band==0)
1340. {
1341. while(aux!=1)
1342. {
1343. for (i=0;i<num-1;i++)
1344. {
1345. mat[i][cont]=mat[i+1][cont-1]-
mat[i][cont-1];
1346. if(mat[i][cont]==0)
1347. aux=1;
1348. }
1349. num--;
1350. if(mat[i][cont]!=0)
1351. cont++;
1352. }
1353.
1354. auxcont=cont;
1355. for (i=0;i<auxnum;i++)
1356. {
1357. printf("\n");
1358. for (j=0;j<cont;j++)
1359. {
1360. if (aux2!=1)
1361. if (j==(cont-
1) && mat[i][j]==1)
1362. {
1363. aux2=1;
1364. cont--;
1365. }
1366. if (aux2!=1)
1367. printf("%10.1f",mat[i][j]);
1368. if (cont2>0)
1369. printf("%10.1f",mat[i][j]);
1370. }
1371.
1372. if (aux2==1)
1373. {
1374. cont2=1;
1375. cont--;
1376. }
1377. }
1378.
1379. printf("\n\nPara que valor en x desea calcular y
prima: ");
1380. scanf("%f",&x);
1381. k=(x-mat[0][0])/difaux;
1382. if (auxcont-1<=6){
1383. if (auxcont-1==2){
1384. ao=(1/difaux)*(mat[0][auxcont-1]);
1385. }
1386. if (auxcont-1==3){
1387. ao=(1/difaux)*((mat[0][auxcont-
2])+((2*k-1)*mat[0][auxcont-1]/2));
1388. }
1389. if (auxcont-1==4){
1390. ao=(1/difaux)*((mat[0][auxcont-
3])+((2*k-1)*mat[0][auxcont-2]/2)+((((3*k*k)-
(6*k)+2)*mat[0][auxcont-1])/6));
1391. }
1392. if (auxcont-1==5){
1393. ao=(1/difaux)*((mat[0][auxcont-
4])+((2*k-1)*mat[0][auxcont-3]/2)+((((3*k*k)-
(6*k)+2)*mat[0][auxcont-2])/6)+((((4*k*k*k)-(18*k*k)+(22*k)-
6)*mat[0][auxcont-1])/24));
1394. }
1395. if (auxcont-1==6){
1396. ao=(1/difaux)*((mat[0][auxcont-
5])+((2*k-1)*mat[0][auxcont-4]/2)+((((3*k*k)-
(6*k)+2)*mat[0][auxcont-3])/6)+((((4*k*k*k)-(18*k*k)+(22*k)-
6)*mat[0][auxcont-2])/24)+((((5*k*k*k*k)-(40*k*k*k)+(105*k*k)-
(100*k)+24)*mat[0][auxcont-1])/120));
1397. }
1398. printf("f'(%.1f)= %f",x,ao);
1399. }
1400. if(auxcont-1>6){
1401. printf("son muchas diferencias para
este programa");
1402. }
1403. }
1404.
1405. if (band==1)
1406. printf("Error el intervalo h entre puntos es
diferente");
1407.
1408. system("pause");
1409. return 0;
1410.
1411. }
1412. double ftres(double x)
1413. {
1414. return (x*x);
1415. }
1416.
1417. int Trapecio_Funcion()
1418. {
1419. int n, i;
1420. float a, b, h, area,x, sum;
1421.
1422. sum=0;
1423. cout<<"teclear valor de a:"<<endl;
1424. cin>>a;
1425. cout<<"teclear valor de b:"<<endl;
1426. cin>>b;
1427. do
1428. {
1429. cout<<"teclear numero de puntos:"<<endl;
1430. cin>>n;
1431. }while(n<=0);
1432. printf("\n\n x y Fm Produc
to\n\n");
1433. float y[n-1];
1434.
1435.
1436. h=(b-a)/(n-1);
1437. x=a;
1438. i=0;
1439. do
1440. {
1441. y[i]=ftres(x);
1442. if(i>0 && i<n-1)
1443. {
1444. printf("%10.4f%10.4f 2 %f
\n",x,y[i], (2*y[i]));
1445.
1446. }
1447. else
1448. {
1449. printf("%10.4f%10.4f 1 %f
\n",x ,y[i], y[i]);
1450.
1451. }
1452. i=i+1;
1453. x=x+h;
1454. }while(i<=n-1);
1455.
1456. area=y[0]+y[n-1];
1457. for(i=1;i<n-1;i++)
1458. area=area+2*y[i];
1459.
1460. area=area*h/2;
1461. sum=area*2/h;
1462. cout<<" Sumatoria: "<<sum<<endl;
1463.
1464. cout<<" Area: "<<area<<endl;
1465. system("pause");
1466. return 0;
1467. }
1468.
1469. int Trapecio_Tabla()
1470. {
1471. int n, i;
1472. float a, b, h, area, sum;
1473.
1474. sum=0;
1475. cout<<"teclear valor de a:"<<endl;
1476. cin>>a;
1477. cout<<"teclear valor de b:"<<endl;
1478. cin>>b;
1479. do
1480. {
1481. cout<<"teclear numero de puntos:"<<endl;
1482. cin>>n;
1483. }while(n<=0);
1484.
1485. float x[n-1], y[n-1];
1486. for(i=0; i<=n-1; i++)
1487. {
1488. printf("\nTeclea x%d: ", i+1);
1489. scanf("%f", &x[i]);
1490. printf("Teclea y%d: ", i+1);
1491. scanf("%f", &y[i]);
1492. }
1493.
1494. h=(b-a)/(n-1);
1495. area=y[0]+y[n-1];
1496. for (i=1; i<n-1; i++)
1497. area=area+2*y[i];
1498. area=area*h/2;
1499.
1500. printf("\n");
1501. printf(" x y Fm Producto\n
\n");
1502. for(i=0;i<=n-1;i++)
1503. {
1504. if(i>0 && i<n-1)
1505. {
1506. printf("%10.4f%10.4f 2 %f
\n",x[i],y[i], (2*y[i]));
1507.
1508. }
1509. else
1510. {
1511. printf("%10.4f%10.4f 1 %f
\n",x[i],y[i], y[i]);
1512.
1513. }
1514. }
1515. sum=area*2/h;
1516. printf("\n Sumatoria: %f", sum)
;
1517.
1518. printf("\n\nArea: %f\n\n", area);
1519. system("pause");
1520. return 0;
1521.
1522. }
1523. double fcuatro(double x)
1524. {
1525. return ((x*x+5)*x);
1526. }
1527.
1528. int simpson_Funcion()
1529. {
1530. double a,b;
1531. int n;
1532. cout <<"Ingrese el valor inferior: ";
1533. cin>>a;
1534. cout <<"Ingrese el valor superior: ";
1535. cin>>b;
1536. bool impar=true;
1537. do{
1538. cout<<"Ingrese un numero impar mayor que 1: ";
1539. cin>>n;
1540. if(n%2!=0 && n>1)
1541. impar=false;
1542. }while(impar);
1543.
1544. double x=a,y[n],h=(b-a)/(n-1);
1545. int fm[3]={1,2,4};
1546. int i=1;
1547. cout<<"\n --------------------------------------------
--------------------";
1548. cout<<"\n n x y fm
producto";
1549. cout<<"\n --------------------------------------------
--------------------"<<endl;
1550. do{
1551. y[i]=fcuatro(x);
1552. // cout<<" "<<x<<" "<<y[i]<<endl;
1553. printf("%10i%14.6f%14.6f",i,x,y[i]);
1554. if(i==1 || i==n){
1555. printf("%10i%14.6f",fm[0],y[i]*fm[0]);
1556. }
1557. else if(i%2==0){
1558. printf("%10i%14.6f",fm[2],y[i]*fm[2]);
1559. }
1560. else {
1561. printf("%10i%14.6f",fm[1],y[i]*fm[1]);
1562. }
1563. cout<<endl;
1564. i=i+1;
1565. x=x+h;
1566. }while(i<=n);
1567. // cout<<" "<<x<<" "<<y[i]<<endl;
1568.
1569. double area=y[1]+y[n];
1570. for(i=2; i<n; i++){
1571. if(i%2==0)
1572. area=area+4*y[i];
1573. else
1574. area=area+2*y[i];
1575. }
1576. area=area*h/3;
1577. cout <<endl;
1578. cout<<"\tarea= "<<area<<endl;
1579. system("pause");
1580. return 0;
1581. }
1582.
1583. int Simpson_Tabla()
1584. {
1585. int n;
1586. double a,b,h;
1587. cout <<"Ingrese el valor inferior: ";
1588. cin>>a;
1589. cout <<"Ingrese el valor superior: ";
1590. cin>>b;
1591. bool impar=true;
1592. do{
1593. cout<<"Ingrese un numero impar mayor que 1: "<<endl;
1594. cin>>n;
1595. if(n%2!=0 && n>1)
1596. impar=false;
1597. }while(impar);
1598.
1599. h=(b-a)/(n-1);
1600.
1601. double y[n];
1602. for(int i=1; i<=n; i++){
1603. cout<<"Ingrese el valor de Y["<<i<<"]: ";
1604. cin>>y[i];
1605. }
1606. double area=y[1]+y[n];
1607.
1608. for(int i=2; i<n; i++){
1609. if(i%2==0)
1610. area=area+4*y[i];
1611. else
1612. area=area+2*y[i];
1613. }
1614.
1615. area=area*h/3;
1616. cout <<endl;
1617. cout<<"\tarea= "<<area<<endl;
1618.
1619. system("pause");
1620.
1621. return 0;
1622.
1623. }
1624. double hl(double x, double y)
1625. {
1626. return (2*x*y);
1627. }
1628.
1629. int euler()
1630. {
1631. int n,i=0;
1632. double x,y,vc,h;
1633.
1634. cout<<"\nIngrese las condiciones iniciales"<<endl;
1635. cout<<"\nIngrese el valor de X0 : ";
1636. cin>>x;
1637. cout<<"Ingrese el valor de Y0 : ";
1638. cin>>y;
1639. cout<<"Ingrese el valor a calcular : ";
1640. cin>>vc;
1641. cout<<"Ingrese el numero de iteraciones : ";
1642. cin>>n;
1643.
1644. h=(vc-x)/n;
1645.
1646. cout<<"\n --------------------------------------";
1647. cout<<"\n n Xn Yn ";
1648. cout<<"\n --------------------------------------
"<<endl;
1649.
1650. printf("%10i%14.6f%14.6f",i,x,y);
1651. cout<<endl;
1652. do{
1653. y=y+h*hl(x,y);
1654. i=i+1;
1655. x=x+h;
1656. printf("%10i%14.6f%14.6f",i,x,y);
1657. cout<<endl;
1658.
1659. }while(i<n);
1660.
1661. cout<<"\nResultado : "<<y<<endl;
1662. system("pause");
1663. return 0;
1664. }
1665.
1666. int euler_mejorado()
1667. {
1668. int n,i=0;
1669. double x0,x1,y0,y1,y2,vc,h;
1670.
1671. cout<<"\nIngrese las condiciones iniciales"<<endl;
1672. cout<<"\nIngrese el valor de X0 : ";
1673. cin>>x0;
1674. cout<<"Ingrese el valor de Y0 : ";
1675. cin>>y0;
1676. cout<<"Ingrese el valor a calcular : ";
1677. cin>>vc;
1678. cout<<"Ingrese el numero de iteraciones : ";
1679. cin>>n;
1680.
1681. h=(vc-x0)/n;
1682.
1683. cout<<"\n --------------------------------------";
1684. cout<<"\n n Xn Yn ";
1685. cout<<"\n --------------------------------------
"<<endl;
1686.
1687. printf("%10i%14.6f%14.6f",i,x0,y0);
1688. cout<<endl;
1689. do{
1690. x1=x0+h;
1691. y1=y0+h*hl(x0,y0);
1692. y2=y0+(h/2)*(hl(x0,y0)+hl(x1,y1));
1693. i=i+1;
1694. x0=x1;
1695. y0=y2;
1696. printf("%10i%14.6f%14.6f",i,x1,y2);
1697. cout<<endl;
1698.
1699. }while(i<n);
1700.
1701. cout<<"\nResultado : "<<y2<<endl;
1702. system("pause");
1703. return 0;
1704.
1705. }
1706.
1707. void menu_Raices()
1708. {
1709. bool repite= true;
1710. int opcion;
1711.
1712. do{
1713. system("cls");
1714.
1715. //el titulo del menu
1716. cout <<"Metodos De Solucion De Raices"<<endl;
1717.
1718. //las opciones del menu
1719. cout << "\t0.- Regresar a menu principal"<<endl;
1720. cout << "\t1.- Metodo De Biseccion\n";
1721. cout << "\t2.- Metodo De Falsa Posicion\n";
1722. cout << "\t3.- Metodo De La Secante\n";
1723. cout << "\t4.- Metodo De Newton-Raphson\n";
1724. cout << "\t5.- Metodo De Newton De segundo
Orden\n";
1725.
1726.
1727. //leer la opcion elegida por el usuario
1728. cout << "\n\Elegir opicion:"<<endl;
1729. cin >> opcion;
1730.
1731.
1732. switch (opcion){
1733. case 1:
1734. Biseccion();
1735. break;
1736.
1737. case 2:
1738. Fpos();
1739. break;
1740.
1741. case 3:
1742. Secante();
1743. break;
1744.
1745. case 4:
1746. Newton_Raphson();
1747. break;
1748.
1749. case 5:
1750. Newton_2do_Orden();
1751. break;
1752.
1753.
1754. case 0:
1755. repite = false;
1756. break;
1757.
1758. default:
1759. system("cls");
1760. cout << "\n\Esa opcion no es
valida"<<endl;
1761. system("pause>nul");
1762. break;
1763. }
1764.
1765. }while (repite);
1766. }
1767.
1768. void menu_Ecuaciones()
1769. {
1770. bool repite= true;
1771. int opcion;
1772. do{
1773. system("cls");
1774.
1775.
1776. cout << "\n\t\t\tMetodos de solucion de
ecuaciones lineales"<<endl;
1777.
1778.
1779. cout << "\n\t0.- Regresar a menu pricipal\n";
1780. cout << "\t1.- Metodo De Gauss\n";
1781. cout << "\t2.- Metodo De Gauss-Jorda\n";
1782. cout << "\t3.- Metodo De Montante\n";
1783. cout << "\t4.- Metodo De Cramer\n";
1784. cout << "\t5.- Metodo De Jacobi\n";
1785. cout << "\t6.- Metodo De Gauss_Seidel\n";
1786.
1787.
1788.
1789. cout << "\n\t Opcion: ";
1790. cin >> opcion;
1791.
1792.
1793. switch (opcion){
1794. case 1:
1795. Gauss();
1796. do{
1797. cout<<"\nconservar matriz existente:(1=si)(2=no)"<<endl;
1798. cin>>respg;
1799. }
1800. while(respg!=1 && respg!=2);
1801. system("CLS");
1802. break;
1803.
1804. case 2:
1805. Gauss_Jordan();
1806. do{
1807. cout<<"\nconservar matriz existente:(1=si)(2=no)"<<endl;
1808. cin>>respg;
1809. }
1810. while(respg!=1 && respg!=2);
1811. system("CLS");
1812. break;
1813.
1814. case 3:
1815. Montante();
1816. do{
1817. cout<<"\nconservar matriz existente:(1=si)(2=no)"<<endl;
1818. cin>>respg;
1819. }
1820. while(respg!=1 && respg!=2);
1821. system("CLS");
1822. break;
1823.
1824. case 4:
1825. Cramer();
1826. do{
1827. cout<<"\nconservar matriz existente:(1=si)(2=no)"<<endl;
1828. cin>>respg;
1829. }
1830. while(respg!=1 && respg!=2);
1831. system("CLS");
1832. break;
1833.
1834. case 5:
1835. Jacobi();
1836. do{
1837. cout<<"\nconservar matriz existente:(1=si)(2=no)"<<endl;
1838. cin>>respg;
1839. }
1840. while(respg!=1 && respg!=2);
1841. system("CLS");
1842. break;
1843.
1844. case 6:
1845. Gauss_Seidel();
1846. do{
1847. cout<<"\nconservar matriz existente:(1=si)(2=no)"<<endl;
1848. cin>>respg;
1849. }
1850. while(respg!=1 && respg!=2);
1851. system("CLS");
1852. break;
1853.
1854. case 0:
1855. repite = false;
1856. break;
1857.
1858. default:
1859. system("cls");
1860. cout << "\n\t\t\tEsa opcion no existe\n";
1861. system("pause>nul");
1862. break;
1863. }
1864.
1865. }while (repite);
1866.
1867. }
1868.
1869. void menu_Interpolacion()
1870. {
1871. bool repite= true;
1872. int opcion;
1873.
1874.
1875. do{
1876. system("cls");
1877.
1878.
1879. cout << "\n\t\t\t Metodos De Interpolacion
Lineal\n";
1880.
1881.
1882. cout << "\n\t0.- Regresar\n";
1883. cout << "\t1.- Metodo De Newton\n";
1884. cout << "\t2.- Metodo De Lagrange\n";
1885. cout << "\t3.- Metodo De Minimos Cuadrados\n";
1886.
1887.
1888.
1889. cout << "\n\tOpcion: ";
1890. cin >> opcion;
1891.
1892.
1893. switch (opcion){
1894. case 1:
1895. ILNewton();
1896. break;
1897.
1898. case 2:
1899. Lagrange();
1900. break;
1901.
1902. case 3:
1903. Minimos_Cuadrados();
1904. break;
1905.
1906. case 0:
1907. repite = false;
1908. break;
1909.
1910. default:
1911. system("cls");
1912. cout << "\n\t\t\tEsa opcion no existe\n";
1913. system("pause>nul");
1914. break;
1915. }
1916.
1917. }while (repite);
1918.
1919. }
1920.
1921.
1922. void menu_Dif_E_Int()
1923. {
1924. bool repite= true;
1925. int opcion;
1926.
1927.
1928. do{
1929. system("cls");
1930.
1931.
1932. cout << "\n\t\t\t Metodos De Diferenciacion e
Integracion\n";
1933.
1934.
1935. cout << "\n\t0.- Regresar\n";
1936. cout << "\t1.- Derivada Por Limites\n";
1937. cout << "\t2.- Diferenciacion Numerica por medio
de Diferencias Finitas\n";
1938. cout << "\t3.- Integracion por el metodo del
trapecio en base a una funcion\n";
1939. cout << "\t4.- Integracion por el metodo del
trapecio en base a una tabla de valores\n";
1940. cout << "\t5.- Integracion por el metodo de
Simpson en base a una funcion\n";
1941. cout << "\t6.- Integracion por el metodo de
Simpson en base a una tabla de valores\n";
1942.
1943.
1944.
1945.
1946. cout << "\n\t Elige una Opcion: ";
1947. cin >> opcion;
1948.
1949.
1950. switch (opcion){
1951. case 1:
1952. Derivada_Por_Limites();
1953. break;
1954.
1955. case 2:
1956. Diferencias_Finitas();
1957. break;
1958.
1959. case 3:
1960. Trapecio_Funcion();
1961. break;
1962.
1963. case 4:
1964. Trapecio_Tabla();
1965. break;
1966.
1967. case 5:
1968. simpson_Funcion();
1969. break;
1970.
1971. case 6:
1972. Simpson_Tabla();
1973. break;
1974.
1975.
1976.
1977. case 0:
1978. repite = false;
1979. break;
1980.
1981. default:
1982. system("cls");
1983. cout << "\n\t\t\tEsta opcion no
existe\n";
1984. system("pause>nul");
1985. break;
1986. }
1987.
1988. }while (repite);
1989.
1990. }
1991.
1992. void menu_ecuaciones()
1993. {
1994. bool repite= true;
1995. int opcion;
1996.
1997.
1998. do{
1999. system("cls");
2000.
2001.
2002. cout << "\n\t\t\t Metodos De Ecuaciones
Diferenciales\n";
2003.
2004.
2005. cout << "\n\t0.- Regresar\n";
2006. cout << "\t1.- Metodo de euler\n";
2007. cout << "\t2.- Metodo de euler mejorado\n";
2008.
2009.
2010.
2011.
2012.
2013. cout << "\n\t Elige una Opcion: ";
2014. cin >> opcion;
2015.
2016.
2017. switch (opcion){
2018. case 1:
2019. euler();
2020. break;
2021.
2022. case 2:
2023. euler_mejorado();
2024. break;
2025.
2026.
2027.
2028.
2029.
2030. case 0:
2031. repite = false;
2032. break;
2033.
2034. default:
2035. system("cls");
2036. cout << "\n\t\t\tEsta opcion no
existe\n";
2037. system("pause>nul");
2038. break;
2039. }
2040.
2041. }while (repite);
2042.
2043. }
2044.
2045. void menu_principal()
2046. {
2047. bool repite= true;
2048. int opcion;
2049.
2050. do{
2051. system("cls");
2052. cout<<"\n\t\t\tMETODOS NUMERICOS"<<endl;
2053. cout<<"ING. Jesus Astolfo Rodriguez
Valenzuela"<<endl;
2054. cout<<"Carrera: Mecatronica"<<endl;
2055. cout<<"Equipo #7:"<<endl;
2056. cout<<"Fernando Lopez Beltran"<<endl;
2057. cout<<"Jose Crisanto Landeros Vega"<<endl;
2058. cout<<"Carlos Alberto Hernandez Beltran"<<endl;
2059. cout<<"Baudelio Guadalupe Monzon Montoya"<<endl;
2060.
2061.
2062. cout << "\n\t\t\tMETODOS NUMERICOS\n";
2063.
2064.
2065. cout << "\n\t0.- Salir\n";
2066. cout << "\t1.- Solucion de Raices\n";
2067. cout << "\t2.- Solucion de Ecuaciones
Lineales\n";
2068. cout << "\t3.- Interpolacion Lineal\n";
2069. cout << "\t4.- Diferenciacion e Integracion\n";
2070. cout << "\t5.- Ecuaciones diferenciales\n";
2071.
2072.
2073.
2074. cout << "\n\tEliga una opcion: ";
2075. cin >> opcion;
2076.
2077.
2078. switch (opcion){
2079. case 1:
2080. menu_Raices();
2081. break;
2082.
2083. case 2:
2084. menu_Ecuaciones();
2085. break;
2086.
2087. case 3:
2088. menu_Interpolacion();
2089. break;
2090.
2091. case 4:
2092. menu_Dif_E_Int();
2093. break;
2094. case 5:
2095. menu_ecuaciones();
2096.
2097. break;
2098.
2099. case 0:
2100. repite = false;
2101. break;
2102.
2103. default:
2104. system("cls");
2105. cout << "\n\t\t\tEsta opcion no
existe\n";
2106. system("pause>nul");
2107. break;
2108. }
2109.
2110. }while (repite);
2111.
2112. }
2113. int main() {
2114. menu_principal();
2115. return 0;
2116. }

También podría gustarte