Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.c
- // assignment_3
- //
- // Created by Jetse Koopmans on 01-10-12.
- // Copyright (c) 2012 Jetse Koopmans. All rights reserved.
- //
- #include <stdio.h>
- #include <math.h>
- #include "Header.h"
- /*int main(int argc, const char * argv[])
- {
- // insert code here...
- printf("\tTesting\n\n");
- printf("\tf'(t)=1\tt0=0 t/m t1=10 with y0=0\n");
- for (double i = 0.1 ; i > 0.0001 ; i /= 10) {
- testallmethods(f1, 0, 10, 0, i, 50);
- }
- }
- */
- int f1 (double t, double * y0, double * dy, void * s) {
- dy[0]=t;
- return 0;
- }
- #define MAX 99999
- float equation(float x,float y)
- {
- return(x);
- }
- int main()
- {
- //float x = 0, y =;
- int i=1,count=1;
- float lower = 0,upper = 10,y1 = 0,h = 0.1,xvalue[MAX],yvalue[MAX];
- float s,s1,s2;
- printf("\n\n");
- printf("Runge-Kutta Second Order ");
- printf("\n\n");
- xvalue[i]=lower;
- yvalue[i]=y1;
- for(i=1;xvalue[i]<=upper;i++)
- {
- xvalue[i+1]=xvalue[i]+h;
- count=count+1;
- }
- for(i=1;i<=count;i++)
- {
- s1=equation(xvalue[i],yvalue[i]);
- s2=equation(xvalue[i]+h,yvalue[i]+(h*s1));
- s=(s1+s2)/2;
- yvalue[i+1]=yvalue[i]+(h*s);
- }
- printf("\n\n");
- printf("The complete solution of the differential equation is ");
- printf("\n\n");
- for(i=1;i<=count;i++)
- {
- printf(" %d %.4f %.4f ",i,xvalue[i],yvalue[i]);
- printf("\n");
- }
- }
Add Comment
Please, Sign In to add comment