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

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 ||
Create a java Swing GUI application that presents the user with a “fortune”. Create a java...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java Swing GUI application in a new Netbeans project called FortuneTeller. Your project will have a FortuneTellerFrame.java class (which inherits from JFrame) and a java main class: FortuneTellerViewer.java. Your application should have and use the following components: Top panel: A JLabel with text “Fortune Teller” (or something similar!) and an ImageIcon. Find an appropriate non-commercial Fortune Teller image for your ImageIcon. (The JLabel has a...
Solve differential equation: y'+y=sin(x)
Solve differential equation: y'+y=sin(x)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT