Sunday, November 5, 2017

Day 3 - Numerical Technique: Linear Interpolation, Math Functions. Brinicles and Open Jet Engines

CLASSWORK/ HOMEWORK:
Freezing Temperature of Seawater
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
/*  This program uses linear interpolation to                  */
/*  compute the freezing temperature of seawater.              */
#include <stdio.h> 
#include <math.h>
int main(void)
{
/*  Declare variables.  */
double salinity_a, freezpt_a, new_salinity_b, freezpt_b, salinity_c, freezpt_c;
/*  Get user input from the keyboard.  */
printf("Use ppt for salinity values. \n");
printf("Use degrees F for temperatures. \n");
printf("Enter first salinity and freezing temperature: \n");
scanf("%lf %lf",&salinity_a,&freezpt_a);
printf("Enter second salinity and freezing temperature: \n");
scanf("%lf %lf",&salinity_c,&freezpt_c);
printf("Enter new salinity: \n");
scanf("%lf",&new_salinity_b);
//  Use linear interpolation to compute   new freezing temperature.            
freezpt_b = freezpt_a + (new_salinity_b - salinity_a)/(salinity_c - salinity_a)*(freezpt_c - freezpt_a);
/*  Print new freezing temperature.  */
printf("New freezing temperature in degrees F: %4.1f \n",freezpt_b);
return 0;  /*  Exit program.  */

}

Open Jet Engine Velocity and Acceleration
#include <math.h>
#include <stdio.h>

int main(void)
{
  double Velocity,acceleration, t_s;
  printf("Input time elapsed in seconds:\n");
  scanf("%lf",&t_s);
  Velocity = .00001*(t_s*t_s*t_s)-.00488*(t_s*t_s)+.75795*(t_s)+181.3566;
  acceleration = 3-.000062*(Velocity*Velocity);
  printf("Velocity:%lf m/s\n", Velocity);
  printf("Acceleration: %lf m/s/s\n",acceleration);
 return 0;

}

Logarithm of Base 'y'
#include <stdio.h>
#include <math.h>

int main (void)
{
 double x, y, log_y;
 printf("Logarithm of x to Base y: \n");
 printf("\nInput positive numbers for x & y: \n");
 scanf("%lf" "%lf",&x, &y);
 log_y = log(x)/log(y);
 if (x <= 0 || y <= 0)
 {
  printf("Sorry, please input a positive number. \n");
 } 
 else
 {
  printf("The logarithm of x to base y is %5.1f \n", log_y);
 }
 return 0;

}

No comments:

Post a Comment