Question

In: Computer Science

Create a java application that can solve the following differential equation and boundary condition with the...

Create a java application that can solve the following differential equation and boundary condition with the Runge Kutta method and the secant method.

x' = f(t,x) = x + 0.09x2 + cos(10*t) differential equation

x(0) + x(1) - 3.0 = 0            boundary condition

Starting with the initial guesses 0.7 and 1.0 for the (unknown) initial value, x(0), obtain an approximation to x(0) {for the final solution, x(t)} such that the boundary condition is satisfied to within a tolerance of 10-4 . Use a fixed stepsize of 0.025 (i.e., take 40 steps each time you integrate the differential equation from t=0 to t=1). Write your program so that the output shows the values of x(0), x(1), and x(0)+x(1)-3 (the error in satisfying the boundary condition) at the end of each iteration of the secant method. After the last iteration of the secant method, re-integrate from t=0 to t=1 and print out the solution for x(t) over the range [0,1]. Your solution for x(t) should resemble the solution plotted below.

You approximation to x(0), when you finish, should be roughly 0.7378743818.

Solutions

Expert Solution

Here I am providing the java code. Hope it helps. Please like my answer for my work. If any doubts please comment. I will help in clearing it.

* This problem uses Euclid's method and the fourth
* order Runge-Kutta method to compute at x=1
* for the D.E. dy/dx = x + 0.09 x 2 + cos(10 t)
* with initial value x = 0 to x = 1 and t = 0 to t = 1
public class RungeKutta
{
// The number of steps to use in the interval
public static final int STEPS = 100;

// The derivative dy/dx at a given value of x and y.
public static double deriv(double x, double y)
{
return x + Math.sqrt(0.09*2)+ cos(10t);
}

// The `main' method does the actual computations
public static void main(String[] argv)
{
// `h' is the size of each step.
double h = 1.0 / STEPS;
double k1, k2, k3, k4;
double x, y;
int i;

// Computation by Euclid's method
// Initialize y
y = 0;
for (i=0; i<STEPS; i++)
{
// Step through, updating x and incrementing y
x = i * h;
y += h * deriv(x, y);
}
// Print out the result that we get.
System.out.println("Using the Euler method "
+ "The value at x=1 is:");
System.out.println(y);

// Computation by 4th order Runge-Kutta
// Initialize y
y = 0;
for (i=0; i<STEPS; i++)
{
// Step through, updating x
x = i * h;
// Computing all of the trial values
k1 = h * deriv(x, y);
k2 = h * deriv(x + h/2, y + k1/2);
k3 = h * deriv(x + h/2, y + k2/2);
k4 = h * deriv(x + h, y + k3);
// Incrementing y
y += k1/6 + k2/3+ k3/3 + k4/6;
}
// Print out the result that we get.
System.out.println();
System.out.println("Using 4th order Runge-Kutta "
+ "The value at x=1 is:");
System.out.println(y);

// Computation by closed form solution
// Print out the result that we get.
System.out.println();
System.out.println("The value really is:");
y = (Math.exp(0.5) - Math.exp(-0.5)) / 2;
System.out.println(y);
}
}

Thank you. Please like.


Related Solutions

Solve the following ordinary differential equations by separating variables and integration. 1. y'sinx=ylny, the boundary condition...
Solve the following ordinary differential equations by separating variables and integration. 1. y'sinx=ylny, the boundary condition (b.c.) is that the function passes through (y=e,x=pi/3) 2. y'+2xy2=0, b.c. (y=1;x=2) 3. y'-xy=x, b.c. (y=1;x=0)
convert differential equation to a matrix differential equation? can put an example and solve it.
convert differential equation to a matrix differential equation? can put an example and solve it.
This is a Matlab Question Create MATLAB PROGRAM that can solve First Order Linear Differential Equation...
This is a Matlab Question Create MATLAB PROGRAM that can solve First Order Linear Differential Equation ( 1 example contains condition and the other does not have condition). 1. ty′ + 2y = t^2 − t + 1, y(1)=12 The correct answer is y(t) = 1/4 t^2 − 1/3 t + 1/2 + 1/12t^2 2. (x-1) dy/dx + 2y = (x+1)^2 The correct answer is y = (x(x+1) / x-1 ) + C(x+1) / x-1 The correct answer is
Solve the following problems. a) What is the order of the differential equation ? ′ =...
Solve the following problems. a) What is the order of the differential equation ? ′ = ? 2 − 3? − 10? Is it linear ? b) Determine whether the differential equation ? ′ = ? 2 − 3? − 10 possesses constant solutions. If yes find these constant solutions. c) Find the value(s) of ? so that the function ? = ? ?? is a solution of ? ′′ − 3? ′ − 10? = 0. Do you think...
solve the differential equation a) ? ′′ − ? ′ = 1 1 + ? −?...
solve the differential equation a) ? ′′ − ? ′ = 1 1 + ? −? b) ? ′′ + 3? ′ + 2? = cos(?x ) c) 10) ? ′′ − 2? ′ + ? = exsqrtx
Series Solutions of Ordinary Differential Equations For the following problems solve the given differential equation by...
Series Solutions of Ordinary Differential Equations For the following problems solve the given differential equation by means of a power series about the given point x0. Find the recurrence relation; also find the first four terms in each of two linearly independent solutions (unless the series terminates sooner). If possible, find the general term in each solution. (1-x)y"+xy-y=0, x0=0
Series Solutions of Ordinary Differential Equations For the following problems solve the given differential equation by...
Series Solutions of Ordinary Differential Equations For the following problems solve the given differential equation by means of a power series about the given point x0. Find the recurrence relation; also find the first four terms in each of two linearly independent solutions (unless the series terminates sooner). If possible, find the general term in each solution. (4-x2)y"+2y=0, x0
In Exercises 1-38, solve each differential equation using variation of parameters. If an equation can be...
In Exercises 1-38, solve each differential equation using variation of parameters. If an equation can be solved using undetermined coefficients, do so. If both methods can be used to find Yp, which method is easier when both can be used? y"+2y'+50y=e^(-t)csc(7t)
Solve the differential equation Y’(t) = AY(t), with initial condition Y(0) = [1;0] (a 2x1 matrix);...
Solve the differential equation Y’(t) = AY(t), with initial condition Y(0) = [1;0] (a 2x1 matrix); where A = [ 9 , 5 ; -6 , -2 ]. Then, using Euler’s method with step size h=.1 over [ 0 , .5 ] fill in the table with header where the 2x1 matrix Yi is the approximation of the exact solution Y(ti) : t Yi Y(ti) ||Y(ti) – Yi ||
Java Please comment code Create an Interactive JavaFX Application Create an application with the following controls:...
Java Please comment code Create an Interactive JavaFX Application Create an application with the following controls: A Label control with the following text displayed: "First Number:" A Label control with the following text displayed: "Second Number:" An empty TextField control beside the First Number label. An empty TextField control beside the Second Number label. Five buttons: Button 1 labeled + Button 2 labeled - Button 3 labeled * Button 4 labeled / Button 5 labeled = An empty Label control...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT