Question

Task 2: (1 Mark) - Scripts Write a MATLAB script which plots the absolute error between your mySqrt() function and the built-

mysqrt.mx + sfunction to reimplement sqrt() function x = mysqrt(n, n, err); xn = n . / 2; for i = 1:N x = 0.5 * (x + (n ./ xn

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thank You.

mysqrt.m

function x = mysqrt( n,N,err )
xn = n./2;
for i=1:N
x=0.5 *(xn+(n./xn));
if abs(x-xn)<err
return
end
xn = x;
end

end

script.m

clc
clear
n = 323158;
err = 1e-3;
data = zeros(1,20);
for N=1:20
myRoot = mysqrt(n,N,err);
inbuiltRoot = sqrt(N);
data(N) = abs(myRoot-inbuiltRoot);
end

x = 1:20;
semilogy(x,data);

output

Figure 1 Х G U File Edit View Insert Tools Desktop Window Help akpo 105 АКРО ticci and Wind =_wo m 104 = (n. qrt yRC 103 102

Add a comment
Know the answer?
Add Answer to:
Task 2: (1 Mark) - Scripts Write a MATLAB script which plots the absolute error between...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please follow following scripts: Script for part A:Script for Part B: Matlab Exercises 1. Find the...

    Please follow following scripts: Script for part A:Script for Part B: Matlab Exercises 1. Find the determinant (command: det(A)) and the condition number (command: cond(A)) of the Hilbert matrix H of order k (command: hilb(k)), for k = 1,2, ..., 10. Plot the determinant and the condition number as a function of k using a logarithmic scale for the vertical axis. Hint: The template to help you with this homework assignment is homework/hw15.m. 2. Determine if y is in the...

  • Use matlab a) Create a simulated data set b) Create a set of plots to determine...

    Use matlab a) Create a simulated data set b) Create a set of plots to determine the best transformation to linearize the data c) Fit a first order polynomial (y mx + b) to the linearized data to find the constants m and b d) Reconstruct the original equation from m and b in the linear fitted polynomial e) Plot the fitted equation. Radioactive decay is modeled by the equation: rt where A the amount of mass as a function...

  • Task 2 (25 points + 4 points for commenting): Write computer code to perform the Fixed.Point...

    Task 2 (25 points + 4 points for commenting): Write computer code to perform the Fixed.Point method and use your code to find the root of the following equation using an initial guess of 3 and a stopping criterion of 0.001%; f(x) e -4x For Fixed-Point, you do not have to code Matlab to take the derivatives of the function and check the g'(x). You can do that step by hand, and then show me your hand cal ulations to...

  • 1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector...

    1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector containing the values of the integral (A) for n= 1,2,3,..., n. The function must use the relation (B) and the value of y(1). Your function must preallocate the array that it returns. Use for loop when writing your code. b) Write MATLAB script that uses your function to calculate the values of the integral (A) using the recurrence relation (B), y(n) for n=1,2,... 19...

  • matlab help plz Overview: In this exercise, you will write code to compare how two different mumerical methods (a mi...

    matlab help plz Overview: In this exercise, you will write code to compare how two different mumerical methods (a middle Riemann sum, and MATLAB's integral function) evaluate the function fx) and the x-axis. The code should output the error between the two calculated areas. area between a Function Inputs Func- the function to be numerically integrated. a-the lower interval value. b-the upper interval value. N-the number of rectangles to be used. Function Outputs: Area Riemann- the numerical approximation for the...

  • write MATLAB scripts to solve differential equations. Computing 1: ELE1053 Project 3E:Solving Differential Equations Project Principle...

    write MATLAB scripts to solve differential equations. Computing 1: ELE1053 Project 3E:Solving Differential Equations Project Principle Objective: Write MATLAB scripts to solve differential equations. Implementation: MatLab is an ideal environment for solving differential equations. Differential equations are a vital tool used by engineers to model, study and make predictions about the behavior of complex systems. It not only allows you to solve complex equations and systems of equations it also allows you to easily present the solutions in graphical form....

  • For this project, each part will be in its oun matlab script. You will be uploading a total 3 m f...

    For this project, each part will be in its oun matlab script. You will be uploading a total 3 m files. Be sure to make your variable names descriptive, and add comments regularly to describe what your code is doing and hou your code aligns with the assignment 1 Iterative Methods: Conjugate Gradient In most software applications, row reduction is rarely used to solve a linear system Ar-b instead, an iterative algorithm like the one presented below is used. 1.1...

  • % PA 08: 3D Plots, Files, Functions % Using the script provided and the functions provided,...

    % PA 08: 3D Plots, Files, Functions % Using the script provided and the functions provided, complete the code % to be able to plot specified graphs. Script file contains a menu of % choices where user will select which plot to produce. % Functions contain the necessary code to plot. Please note that functions % do NOT take any arguments and do NOT return anything. % You are provided with two MS Excel files that you must use to...

  • Newton's Method in MATLAB During this module, we are going to use Newton's method to compute...

    Newton's Method in MATLAB During this module, we are going to use Newton's method to compute the root(s) of the function f(x) = x° + 3x² – 2x – 4 Since we need an initial approximation ('guess') of each root to use in Newton's method, let's plot the function f(x) to see many roots there are, and approximately where they lie. Exercise 1 Use MATLAB to create a plot of the function f(x) that clearly shows the locations of its...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT