Question

In: Advanced Math

Starting from mynewton write a function program mysymnewton that takes as its input a symbolic function...

Starting from mynewton write a function program mysymnewton that takes as its input a symbolic function f and the ordinary variables x0 and n. Let the program take the symbolic derivative f ′ , and then use subs to proceed with Newton’s method. Test it on f(x) = x 3 − 4 starting with x0 = 2. Turn in the program and a brief summary of the results

Solutions

Expert Solution

code for matlab is
syms x
f=@(x) x^3-4;
f'=diff(f(x))
h=@(y) subs(f',y)

code for mathematica

f[x_]:=x^3-4

F'[X]                     (*THEN PRESS SHIFT AND ENTER*)

(TO GET THE VALUE FOR XO=2)

F'[2]                (*THEN PRESS SHIFT AND ENTER*)

AND SAVE PROGRAME aS mysymnewton







function [ x, ex ] = newton( f, df, x0, tol, nmax )
%
% NEWTON Newton's Method
%   Newton's method for finding successively better approximations to the 
%   zeroes of a real-valued function.
%
% Input:
%   f - input funtion
%   df - derived input function
%   x0 - inicial aproximation
%   tol - tolerance
%   nmax - maximum number of iterations
%
% Output:
%   x - aproximation to root
%   ex - error estimate
%
% Example:
%       [ x, ex ] = newton( 'x^3-4', 0, 0.5*10^-5, 10 )
%


    if nargin == 3
        tol = 1e-4;
        nmax = 1e1;
    elseif nargin == 4
        nmax = 1e1;
    elseif nargin ~= 5
        error('newton: invalid input parameters');
    end
    
    f = inline(f);
    df = inline(df);
    x(1) = x0 - (f(x0)/df(x0));
    ex(1) = abs(x(1)-x0);
    k = 2;
    while (ex(k-1) >= tol) && (k <= nmax)
        x(k) = x(k-1) - (f(x(k-1))/df(x(k-1)));
        ex(k) = abs(x(k)-x(k-1));
        k = k+1;
    end

end

Related Solutions

Write a program that takes its input from a file of number type double and outputs...
Write a program that takes its input from a file of number type double and outputs the average of the numbers in the file to the screen. The file contains nothing but numbers of the type double separated by blanks and/ or line breaks. If this is being done as a class assignment, obtain the file name from your instructor. File name: pr01hw05input.txt 78.0 87.5 98.1 101.0 4.3 17.2 78.0 14.5 29.6 10.2 14.2 60.7 78.3 89.3 29.1 102.3 54.1...
Write a Java program 1-)write a program that simulates a vending machine, takes input from the...
Write a Java program 1-)write a program that simulates a vending machine, takes input from the user (money), and returns the change to the user. The change means Quarter =   25 cent Dime = 10 cent Nickels = 5 cent Pinneies = 1 cent 2-) What is the output produced by the following code? int result = 11; result /= 2; System.out.println("resu lt is " + result);
write a program that takes the input value from the user and calculate the sum from...
write a program that takes the input value from the user and calculate the sum from that number to zero in MIPS
Write a program that takes a string input from the user and then outputs the first...
Write a program that takes a string input from the user and then outputs the first character, then the first two, then the first three, etc until it prints the entire word. After going up to the full word, go back down to a single letter. LastNameUpDown. Input: Kean Output: K Ke Kea Kean Kea Ke K
Write a C++ program that takes input from the keyboard of the 3 dimensions of a...
Write a C++ program that takes input from the keyboard of the 3 dimensions of a room (W,L,H in feet) and calculates the area (square footage) needed to paint the walls only. Use function overloading in your program to pass variables of type int and double. You should have two functions: one that accepts int datatypes and one that accepts double datatypes. Also assume a default value of 8 if the height parameter is omitted when calling the functions.
Q1-      Write a program that takes a list of values as an input from the user....
Q1-      Write a program that takes a list of values as an input from the user. The program should further ask the user about sorting the list in ascending or descending order. It is desirable to use Arraylist/Vector in place of simple arrays. (Object Oriented Programming java)
Write a function in bash that takes an input temperature (Celsius or Fahrenheit) from the user...
Write a function in bash that takes an input temperature (Celsius or Fahrenheit) from the user converts that temperature Celsius to Fahrenheit, Fahrenheit to Celsius, Celsius to Kelvin and Fahrenheit to Kelvin
Write a program that takes two sets ’A’ and ’B’ as input read from the file...
Write a program that takes two sets ’A’ and ’B’ as input read from the file prog1 input.txt. The first line of the file corresponds to the set ’A’ and the second line is the set ’B’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The output should be written in the file...
Write a C++ program that takes two sets ’A’ and ’B’ as input read from the...
Write a C++ program that takes two sets ’A’ and ’B’ as input read from the file prog1 input.txt. The first line of the file corresponds to the set ’A’ and the second line is the set ’B’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The output should be written in the...
Write a C++ program that takes two sets ’A’ and ’B’ as input read from the...
Write a C++ program that takes two sets ’A’ and ’B’ as input read from the file prog1 input.txt. The first line of the file corresponds to the set ’A’ and the second line is the set ’B’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The output should be written in the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT