Título: Ayuda a completar el Codigo de Minimos cuadrados Publicado por: Carlos Luna en 22 Abril 2012, 19:21 pm http://www.monografias.com/trabajos16/metodos-lineales/metodos-lineales.shtml
Cual seria el siguiente paso a Programar? http://www.monografias.com/trabajos16/metodos-lineales/metodos-lineales.shtml Algun tip para salir de este estanqueamiento de las ecuaciones para encontrar a y b Citar #include<stdio.h> #include<math.h> #include<conio.h> float Ecuacion(float temp,float temp1,float temp2,float temp3,float N); float Sustitucion(float temp,float temp1,float b,float N); int main() { float Matriz[50][51]={0},X[50],Y[50],tm=0,temp=0,temp1=0,temp2=0,temp3=0,N,a,b; int i,j,k,l,x,y,w,n,o=0,p=0; printf("Metodo de Minimos Cuadrados\n\n"); printf("Ingrese el Numero de iteraciones"); scanf("%d",&n); N=n; for(x=0;x<n;x++) { o=o+1; printf("Ingrese datos: X(%d)",o); scanf("%f",&X
for(y=0;y<n;y++) { p=p+1; printf("Ingrese datos: Y(%d)",p); scanf("%f",&Y[y]); } system("cls"); printf("Sus Datos son:\n\n\tXi\tYi\tXiYi\tXi2\n"); for(w=0;w<n;w++) { tm=X[w]; tm=pow(tm,2); Matriz[w][1]=tm; Matriz[w][0]=X[w]*Y[w]; printf("\n\t%.2f \t%.2f \t%.2f \t%.2f\n",X[w],Y[w],Matriz[w][0],Matriz[w][1]); } printf("\n\t+Xi\t+Yi\t+XiYi\t+Xi2\n"); for(i=0;i<n;i++) { temp=temp+X; } for(j=0;j<n;j++) { temp1=temp1+Y[j]; } for(k=0;k<n;k++) { temp2=temp2+Matriz[k][0]; } for(l=0;l<n;l++) { temp3=temp3+Matriz[l][1]; } printf("\n\t%.2f\t%.2f\t%.2f\t%.2f\n\n",temp,temp1,temp2,temp3); printf("Ec.1 ∑y=na+b∑x\nEc.2 ∑xy=a∑x+b∑x˛\n\n"); printf("b=%.5f\n",Ecuacion(temp,temp1,temp2,temp3,N)); b=Ecuacion(temp,temp1,temp2,temp3,N); printf("a=%.5f",Sustitucion(temp,temp1,b,N)); } float Ecuacion(float temp,float temp1,float temp2,float temp3,float N) { float a,b,c,d,e,f,g; a=(temp)*(-temp); b=(temp1)*(-temp); c=(temp3)*(N); d=(temp2)*(N); e=b+d; f=a+c; g=e/f; return g; } float Sustitucion(float temp,float temp1,float b,float N) { float a; a=((b*temp)-temp1)/N; return a; } Hay vamos hay vamos!!! jaja disculpen si me la paso modificando el codigo pero creo que voy progresando Espero sus recomendaciones saludos y Buena vibra! |