Question

In: Advanced Math

The algorithm is basically as follows. The notation is slightly different from that in the website...

The algorithm is basically as follows. The notation is slightly different from that in the website you were given, but there is no difference in the method.

Given the initial value problem

dy/dx=f(x,y),y(a)= y_0

Euler’s Method with step size h consists in applying the iterative formula

y_(n+1)= y_n+h∙f(x_n,y_n ),n≥0

To compute successive approximations y_1,y_2,y_3,⋯ to the (true) values 〖y(x〗_1),〖y(x〗_2),〖y(x〗_3),⋯ of the exact solution y=y(x) at the points x_1,x_2,x_3,⋯, respectively.

In plain English:
You want to approximate the value of dy/dx (or y’) at some point in an interval.

Step 1: Depending on how accurate you need to be, divide the interval up into little pieces of equal length; this length is the step size h. For purposes of discussion, let’s use the interval [0,1] and use ten intervals, so h = 0.1.

Step 2: y_0=0
Step 3: y_1=y_0+0.1f(x_0,y_0)
Step 4: y_2=y_1+0.1f(x_1,y_1)

Stop after ten steps, in this case. Usually the stopping criterion is a level of accuracy.

You can easily set this up in Excel.

Exercises
Use Euler’s Method with step sizes h =0.1,0.02, 0.004, 0.0008 (that is, do the problem 4 times, each with a more precise value of h) , 10 equally spaced iterations.


1. y^'=x^2+y^2,y(0)=0,0≤x≤1

2. y^'=x^2-y^2,y(0)=1,0≤x≤2

3. y^'=ln⁡y,y(1)=2,1≤x≤2

4. y^'=x^(2/3)+y^(2/3),y(0)=1,0≤x≤2

5. y^'=x+√x,y(0)=1,0≤x≤2

6. y^'=x+∛x,y(0)= -1,0≤x≤2

Solutions

Expert Solution


clear all
close all

%function for which Euler method have to calculate
f=@(y,x) x.^2+y.^2;
%all h
hh=[0.1 0.02 0.004 0.0008];
fprintf('For the function f(x,y)=\n')
disp(f)

for i=1:length(hh)
    %step size h
    h=hh(i);
    %initial value
    y0=0; x0=0;
    x_end=1;
    [y1_result,x_result] = euler_method(f,y0,x0,x_end,h);
    figure(1)
    hold on
    plot(x_result,y1_result)
    lgnd{i}=sprintf('For step size %.4f',h);
end
xlabel('x')
ylabel('y(x)')
title('y(x) vs. x plot for function 1')
legend(lgnd)
box on

f=@(y,x) x.^2-y.^2;
%all h
hh=[0.1 0.02 0.004 0.0008];
fprintf('For the function f(x,y)=\n')
disp(f)

for i=1:length(hh)
    %step size h
    h=hh(i);
    %initial value
    y0=1; x0=0;
    x_end=2;
    [y1_result,x_result] = euler_method(f,y0,x0,x_end,h);
    figure(2)
    hold on
    plot(x_result,y1_result)
    lgnd{i}=sprintf('For step size %.4f',h);
end
xlabel('x')
ylabel('y(x)')
title('y(x) vs. x plot for function 2')
legend(lgnd)
box on

f=@(y,x) log(y);
%all h
hh=[0.1 0.02 0.004 0.0008];
fprintf('For the function f(x,y)=\n')
disp(f)

for i=1:length(hh)
    %step size h
    h=hh(i);
    %initial value
    y0=2; x0=1;
    x_end=2;
    [y1_result,x_result] = euler_method(f,y0,x0,x_end,h);
    figure(3)
    hold on
    plot(x_result,y1_result)
    lgnd{i}=sprintf('For step size %.4f',h);
end
xlabel('x')
ylabel('y(x)')
title('y(x) vs. x plot for function 3')
legend(lgnd)
box on

f=@(y,x) x.^(2/3)+y.^(2/3);
%all h
hh=[0.1 0.02 0.004 0.0008];
fprintf('For the function f(x,y)=\n')
disp(f)

for i=1:length(hh)
    %step size h
    h=hh(i);
    %initial value
    y0=1; x0=0;
    x_end=2;
    [y1_result,x_result] = euler_method(f,y0,x0,x_end,h);
    figure(4)
    hold on
    plot(x_result,y1_result)
    lgnd{i}=sprintf('For step size %.4f',h);
end
xlabel('x')
ylabel('y(x)')
title('y(x) vs. x plot for function 4')
legend(lgnd)
box on

f=@(y,x) x+sqrt(x);
%all h
hh=[0.1 0.02 0.004 0.0008];
fprintf('For the function f(x,y)=\n')
disp(f)

for i=1:length(hh)
    %step size h
    h=hh(i);
    %initial value
    y0=1; x0=0;
    x_end=2;
    [y1_result,x_result] = euler_method(f,y0,x0,x_end,h);
    figure(5)
    hold on
    plot(x_result,y1_result)
    lgnd{i}=sprintf('For step size %.4f',h);
end
xlabel('x')
ylabel('y(x)')
title('y(x) vs. x plot for function 5')
legend(lgnd)
box on

f=@(y,x) x+x.^(1/3);
%all h
hh=[0.1 0.02 0.004 0.0008];
fprintf('For the function f(x,y)=\n')
disp(f)

for i=1:length(hh)
    %step size h
    h=hh(i);
    %initial value
    y0=-1; x0=0;
    x_end=2;
    [y1_result,x_result] = euler_method(f,y0,x0,x_end,h);
    figure(6)
    hold on
    plot(x_result,y1_result)
    lgnd{i}=sprintf('For step size %.4f',h);
end
xlabel('x')
ylabel('y(x)')
title('y(x) vs. x plot for function 6')
legend(lgnd)
box on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%Matlab code for Euler's forward
function [y1_result,t_result] = euler_method(f,y0,t0,tend,h)
%function for Euler equation solution
  
    %all step size
    N=(tend-t0)/h;
    %Initial values

    %t end values
    tn=t0:h:tend;
    % Euler steps
    y1_result(1)=y0;
    t_result(1)=t0;
  
    for i=1:length(tn)-1
        t_result(i+1)= t_result(i)+h;
        y1_result(i+1)=y1_result(i)+h*double(f(y1_result(i),t_result(i)));
    end
end

%%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%


Related Solutions

The algorithm is basically as follows. The notation is slightly different from that in the website...
The algorithm is basically as follows. The notation is slightly different from that in the website you were given, but there is no difference in the method. Given the initial value problem dy/dx=f(x,y),y(a)= y_0 Euler’s Method with step size h consists in applying the iterative formula y_(n+1)= y_n+h∙f(x_n,y_n ),n≥0 To compute successive approximations y_1,y_2,y_3,⋯ to the (true) values 〖y(x〗_1),〖y(x〗_2),〖y(x〗_3),⋯ of the exact solution y=y(x) at the points x_1,x_2,x_3,⋯, respectively. In plain English: You want to approximate the value of dy/dx...
Reverse Polish notation is a notation where every operator follows all of its operands. For example,...
Reverse Polish notation is a notation where every operator follows all of its operands. For example, an expression (1+2)*(5+4) in the conventional Polish notation can be represented as 1 2 + 5 4 + * in the Reverse Polish notation. One of advantages of the Reverse Polish notation is that it is parenthesis-free. Write a program which reads an expression in the Reverse Polish notation and prints the computational result. An expression in the Reverse Polish notation is calculated using...
Computation of deferred taxes under IFRS is slightly different from GAAP. For example, in the United...
Computation of deferred taxes under IFRS is slightly different from GAAP. For example, in the United Kingdom (which follows IFRS), companies use the crystallisation approach. An equivalent concept in the United states is “realization”. The concept underlying this “crystallisation” approach is that companies recognize deferred income taxes only if the taxes are expected to crystallize. Therefore, if a liability is deferred indefinitely, then the present value of that liability is zero. No deferred tax liability is recognized if the accumulated...
Computation of deferred taxes under IFRS is slightly different from GAAP. For example, in the United...
Computation of deferred taxes under IFRS is slightly different from GAAP. For example, in the United Kingdom (which follows IFRS), companies use the crystallisation approach. An equivalent concept in the United states is “realization”. The concept underlying this “crystallisation” approach is that companies recognize deferred income taxes only if the taxes are expected to crystallize. Therefore, if a liability is deferred indefinitely, then the present value of that liability is zero. No deferred tax liability is recognized if the accumulated...
Computation of deferred taxes under IFRS is slightly different from GAAP. For example, in the United...
Computation of deferred taxes under IFRS is slightly different from GAAP. For example, in the United Kingdom (which follows IFRS), companies use the crystallization approach. An equivalent concept in the United States is “realization.” The concept underlying this “crystallization” approach is that companies recognize deferred income taxes only if the taxes are expected to crystallize. Therefore, if a liability is deferred indefinitely, then the present value of that liability is zero. No deferred tax liability is recognized if the accumulated...
#72: Note: On this problem, some of your answers might be slightly different from Moodle's because...
#72: Note: On this problem, some of your answers might be slightly different from Moodle's because of rounding error. The table below gives the gold medal times for every other Summer Olympics for the women's 100-meter freestyle (swimming). Year Time (seconds) 1912 82.2 1924 72.4 1932 66.8 1952 66.8 1960 61.2 1968 60.0 1976 55.65 1984 55.92 1992 54.64 2000 53.8 2008 53.1 a. Decide which variable should be the independent variable and which should be the dependent variable. Independent...
(Java)// Slightly different problem from the others that use the same input files, it has been...
(Java)// Slightly different problem from the others that use the same input files, it has been adapted from a practice problem// // Also if you can keep the code as simple as possible, try to avoid any advanced techniques, so that I can easily understand what is happening in case I decide to use this for future reference (which most likely I am) that'd be super appreciated// Deposit and Withdrawal Files: Use Notepad or another text editor to create a...
The number of users of a certain website (in millions) from 2004 through 2011 follows. Year...
The number of users of a certain website (in millions) from 2004 through 2011 follows. Year Period Users (Millions) 2004 1 1 2005 2 6 2006 3 12 2007 4 57 2008 5 144 2009 6 361 2010 7 608 2011 8 846 Using Minitab or Excel, develop a quadratic trend equation that can be used to forecast users (in millions). (Round your numerical values to one decimal place.) Tt = Consider the following time series. Quarter Year 1 Year...
Babylonian Algorithm. The Babylonian algorithm to compute the square root of a positive number n is as follows:
Chapter 3 Exercise 1Babylonian Algorithm. The Babylonian algorithm to compute the square root of a positive number n is as follows:      1. Make a guess at the answer (you can pick n/2 as your initial guess).      2. Computer = n / guess.      3. Set guess = (guess +r) / 2.      4. Go back to step 2 until the last two guess values are within 1% of each other.Write a program that inputs an integer for n, iterates through the Babylonian algorithm until the guess...
Write a RECURSIVE algorithm (different from the ones your provided in 3) implemented in Java a...
Write a RECURSIVE algorithm (different from the ones your provided in 3) implemented in Java a in a complete Java program to reverse a stack of characters using recursion. You are not allowed to use loop constructs like while, for..etc, and you can only use the following functions on Stack S shown below (15pts) Provide an explanation of the running time. You will need to implement your own stack if needed isEmpty(S) push(S) pop(S) Make your own assumption and your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT