Question: ODEs is Ordinary differential equation. #include . #include #include typedef float (function)(float,float); // Declare function signatures float differential(float, float); // y'(x). This is the differential

ODEs is Ordinary differential equation. #include . #include #include typedef float (function)(float,float);ODEs is Ordinary differential equation.

#include . #include  #include  typedef float (function)(float,float); // Declare function signatures float differential(float, float); // y'(x). This is the differential equation. float exactSolution(float); // y(x). This is the equation we approximate with Runge Kutta float RungeKutta(function, float, float, float); // Runge-Kutta average of 4 points float k1(function, float, float); float k2(function, float, float, float); // equations for Runge-Kutta method float k3(function, float, float, float); float k4(function, float, float, float); int main() { float h = 0.01; // Step size float x0 = 0; // This is the initial x value float xf = 1.; // This is the final x value to calculate the approximation up to float y0 = 0; // This is the initial condition, i.e., y(x0) // Input step size and initial conditions printf(" Please enter step size: "); scanf("%f",&h); printf(" Please enter the first x value you would like to calculate from, i.e. x0: "); scanf("%f",&x0); printf(" Please enter the last x value you would like to calculate up to: "); scanf("%f",&xf); printf(" Please enter the initial condition for y, i.e. y(x0): "); scanf("%f",&y0); int arraySize=((xf-x0)/h)+2; // size of arrays for storing the x values and the y values float xValues[arraySize]; // array for storing x values; pgplot can plot these. float yValuesRK[arraySize]; // array for storing y values; pgplot can plot these. float yValuesExact[arraySize]; // array for storing the exact values xValues[0]=x0; //start the x array at the first x value yValuesRK[0]=y0; //start the y array with the given initial condition yValuesExact[0]=y0; //fill the first value of the exact y values // This loop fills the x array with values increasing by h, // and fills the Runge-Kutta y array with values approximated by the Runge-Kutta method. // It also fills yValuesExact with y values calculated with an exact solution to // the differential equation. int i; for (i=1; i 

There have some bug in code, the output of

|Runge Kutta y| alway be 0.
1. Write a routine for finding solutions to coupled ODEs using Runge-Kutta 0 method at 4th order. Ass '(t) f(t, y(t), z(t)), and the initial conditions zo and yo. We know that g(tn yn,2n)- 2n so for example; g(tnk,nn ume that you know the analytic form of 2 Consider a swinging pendulum, whose angle to the horizontal is given by (t). The equation of motion for this system is given by 0 "(t)+gsin e/ e" (t) g/ if we make the small angle approximation. Express this system as a set of coupled ODEs and solve for (t) using a 4th order Runge-Kutta routine up to t = ls (choose h ls), using the initial conditions (0) = /6 and ,(0)-0. Plot the resulting angle as a function of time. (1-0.35m, g 10m/s2) 2. 3. Repeat the above procedure, varying the initial conditions, graphing the results. What do you notice as the initial angle decreases/increases. 4. Increase the maximum time to t = 60s. Is the solution stable? 5. Extension: Repeat the above without assuming the small angle approxi- mation, i.e. using the equation of motion 0-0"(t)+g sin /1 Comment on any differences in the angular trajectory. 0"(t)+9/l

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!