Skip to content

Instantly share code, notes, and snippets.

@IgorDePaula
Created July 21, 2020 23:00
Show Gist options
  • Save IgorDePaula/029f1104cc3d9f744eaef2e7d79ae630 to your computer and use it in GitHub Desktop.
Save IgorDePaula/029f1104cc3d9f744eaef2e7d79ae630 to your computer and use it in GitHub Desktop.
programa do elton
#include <stdio.h>
#include <stdlib.h>
#ifdef __unix__
#define IS_POSIX 1
#else
#define IS_POSIX 0
#endif
double linearInterpolation(double x0, double y0, double x1, double y1, double x) {
return y0 + (y1 - y0) * ((x - x0) / (x1 - x0));
}
void chamaLinearInterpolation(){
float x, x0, y0, x1, y1, i;
int z;
FILE *fp;
printf("Registrar resultado em arquivo? 1-sim; 2-nao: ");
scanf("%d", &z);
printf("Digite o fator X: ");
scanf("%f", &x);
printf("Digite o fator X0: ");
scanf("%f", &x0);
printf("Digite o fator Y0: ");
scanf("%f", &y0);
printf("Digite o fator X1: ");
scanf("%f", &x1);
printf("Digite o fator Y1: ");
scanf("%f", &y1);
i = x0;
while (i <= x1) {
printf("%.lf -> %.3f\n", i, linearInterpolation(x0, y0, x1, y1, i));
if(z == 1){
fp = fopen ("./QUEM ABRIR ISSO EH UMA BICHONA.txt","a+");
fprintf (fp, "%.lf -> %.3f\n", i, linearInterpolation(x0, y0, x1, y1, i));
}
fclose(fp);
i++;
}
printf("\n");
}
void chamaLagrande(){
float x[100],y[100],a,s=1,t=1,k=0;
int n,i,j,d=1;
printf("\n\n Insira o numero de estacas: ");
scanf("%d",&n);
printf("\n\n Entre com o valor da posicao da estaca em (x) ex: 1,2,3...n e a altura (y): \n");
for(i=0; i<n; i++)
{
scanf ("%f",&x[i]);
scanf("%f",&y[i]);
}
printf("\n\n Todos os pontos definidos podem ser vistos a baixo: \n\n");
for(i=0; i<n; i++)
{
printf("%0.3f\t%0.3f",x[i],y[i]);
printf("\n");
}
while(d==1)
{
printf(" \n\n\n Enter the value of the x to find the respective value of y\n\n\n");
scanf("%f",&a);
for(i=0; i<n; i++)
{
s=1;
t=1;
for(j=0; j<n; j++)
{
if(j!=i)
{
s=s*(a-x[j]);
t=t*(x[i]-x[j]);
}
}
k=k+((s/t)*y[i]);
}
printf("\n\n O valor de altura da estaca (y) é: %f",k);
printf("\n\n Do you want to continue?\n\n Press 1 to continue and any other key to exit");
scanf("%d",&d);
}
printf("\n");
}
int main() {
int valor;
printf("***************************************\n");
printf("* PROGRAMA INTERPOLADOR PARA O TCC *\n");
printf("**************************************\n");
printf ("ESCOLHA UMA DAS OPCOES:\n 1 - Interpolar por Lagrande\n 2 - Interpolar por Sistema Linear\n 3 - Informacoes\n 4 - para sair\n Escolha sua opção: ");
scanf("%d", &valor);
while(valor != 4){
if (valor == 1)
{
printf ("1 - Interpolar por Lagrande\n");
chamaLagrande();
}
else
if (valor == 2)
chamaLinearInterpolation();
else
if (valor == 3)
printf ("3 - Informacoes\n");
printf ("ESCOLHA UMA DAS OPCOES:\n 1 - Interpolar por Lagrande\n 2 - Interpolar por Sistema Linear\n 3 - Informacoes\n 4 - para sair\n\n Escolha sua opcao: \n ");
scanf("%d", &valor);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment