Guest User

Untitled

a guest
Dec 11th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.44 KB | None | 0 0
  1. //
  2. //  main.c
  3. //  assignment_3
  4. //
  5. //  Created by Jetse Koopmans on 01-10-12.
  6. //  Copyright (c) 2012 Jetse Koopmans. All rights reserved.
  7. //
  8.  
  9. #include <stdio.h>
  10. #include <math.h>
  11. #include "Header.h"
  12.  
  13. /*int main(int argc, const char * argv[])
  14. {
  15.  
  16.     // insert code here...
  17.     printf("\tTesting\n\n");
  18.     printf("\tf'(t)=1\tt0=0 t/m t1=10 with y0=0\n");
  19.     for (double i = 0.1 ; i > 0.0001 ; i /= 10) {
  20.         testallmethods(f1, 0, 10, 0, i, 50);
  21.     }
  22. }
  23.  */
  24.  
  25. int f1 (double t, double * y0, double * dy, void * s) {
  26.     dy[0]=t;
  27.     return 0;
  28. }
  29.  
  30. #define MAX 99999
  31.  
  32. float equation(float x,float y)
  33. {
  34.     return(x);
  35. }
  36.  
  37. int main()
  38. {
  39.     //float x = 0, y =;
  40.    
  41.    
  42.    
  43.    
  44.     int i=1,count=1;
  45.     float lower = 0,upper = 10,y1 = 0,h = 0.1,xvalue[MAX],yvalue[MAX];
  46.     float s,s1,s2;
  47.     printf("\n\n");
  48.     printf("Runge-Kutta Second Order ");
  49.     printf("\n\n");
  50.     xvalue[i]=lower;
  51.     yvalue[i]=y1;
  52.     for(i=1;xvalue[i]<=upper;i++)
  53.     {
  54.         xvalue[i+1]=xvalue[i]+h;
  55.         count=count+1;
  56.     }
  57.     for(i=1;i<=count;i++)
  58.     {
  59.         s1=equation(xvalue[i],yvalue[i]);
  60.         s2=equation(xvalue[i]+h,yvalue[i]+(h*s1));
  61.         s=(s1+s2)/2;
  62.         yvalue[i+1]=yvalue[i]+(h*s);
  63.     }
  64.     printf("\n\n");
  65.     printf("The complete solution of the differential equation is ");
  66.     printf("\n\n");
  67.     for(i=1;i<=count;i++)
  68.     {
  69.         printf(" %d  %.4f   %.4f  ",i,xvalue[i],yvalue[i]);
  70.         printf("\n");
  71.     }
  72. }
Add Comment
Please, Sign In to add comment