Question

(5 po)A p ia we n prie mer ae 2 7. . 1 1 do aors a d tr e Te Tale the w o md d the t w 2 Fi the wing s Hof te s i a wde th i
( pot) Te of the e 2( Wre a MATLABot tht will lop thh the o a et the apetid te atl v i The 7 5 pt)The vecty oetmige be d
berieal h d dtyThe pllae g wil pmpt the & 0e iat) diy, the lld n to34, i As ithp7 be Te l, ad a the pll a w ld p moe & (as po
10. (35 points) Consider the following relation that determines the positive square value of a, i.e., Va, n 0,1,2, n+1 where
(5 po)A p ia we n prie mer ae 2 7. . 1 1 do aors a d tr e Te Tale the w o md d the t w 2 Fi the wing s Hof te 's i a wde th itaprie For ele, ,the s tpa-2s Th e--2 Therk 2 2 ATLAB d s aw whether the er p le tapr ) M U MATLAB t ces te sod-) fti to dt wtr d y )
( pot) Te of the e 2( Wre a MATLABot tht will lop thh the o a et the apetid te atl v i The 7 5 pt)The vecty oetmige be d
berieal h d dtyThe pllae g wil pmpt the & 0e iat) diy, the lld n to34, i As ithp7 be Te l, ad a the pll a w ld p moe & (as poat) The i wiha pll t 7 d WaATLAB will pia w d wil be prited thema d cotat ecan le
10. (35 points) Consider the following relation that determines the positive square value of a, i.e., Va, n 0,1,2, n+1 where 1 approaches Va as n approaches infinity. Write a MATLAB function mysqrt using while structure to determine the square root of a where the function accepts three inputs (a, epsilon, x0) and the third input is optional and it's default value is ro 0. The header of the function is as follows: function [sqrta,n] mysqrt (a,epsilon, x0) %Returns an approximation of the +ve square root of a % Out puts % sqrta Square root of a % n # of iterations to reach the certain accuracy % Inputs % aA+ve number Desired accuracy % epsilon % xO Initial seed. Optional: default xo o Test the function for v0.25, i.e, a 0.25, with ro 0 and for e 15, 5, 2, and 1%.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

%% MATLAB code begins %%

% Test values
a_test = 0.25;
x0_test = 0;
eps_test = [15, 5, 2, 1];

% Testing
for a = a_test
    for eps = eps_test
        for x0 = x0_test
            fprintf("For a = %f, eps = %f%%, x0 = %f, mysqrt(a) = %f\n", a, eps, x0, mysqrt(a, eps, x0));
        end
    end
end

% Function
function [sqrta, n] = mysqrt(a, epsilon, x0)
    if nargin == 2      % If only 2 args,
        x0 = 0;         % set x0 to default value
    end
    n = 0;              % number of iterations
    sqrta = x0;         % initial value
    epsilon = epsilon / 100 * sqrt(a);      % Doing this will simplify the while condition
    while(abs(sqrt(a) - sqrta) > epsilon)   % While error is unacceptable
        sqrta = sqrta^2 + a;        % Recurrence relation
        n = n + 1;                  % One iteration done
    end
end

%% MATLAB code ends %%

Add a comment
Know the answer?
Add Answer to:
(5 po)A p ia we n prie mer ae 2 7. . 1 1 do aors...
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
  • 5.i) What will be the output of the script: for i-1:7 for j- 1:i fprintf(%d", j)...

    5.i) What will be the output of the script: for i-1:7 for j- 1:i fprintf(%d", j) end fprintf('\n') % start a new line. end 5 (i) For ax2 + bxc 0, the value of x is given by 2a Write a MATLAB function quadrasol () that will have three inputs ( a,b, and c) and two outputs corresponding to the solutions of the equation. It may be more compact if you defined another variable 'd' for the term inside the...

  • MATLAB WORK PLEASE Interest is accrued according to the following formula: A=P i(1 + i)" (1...

    MATLAB WORK PLEASE Interest is accrued according to the following formula: A=P i(1 + i)" (1 + i)" – 1 where A is the annual payment, P is the present worth, i is the interest rate (not in percent), and n is the number of years. You decide to buy a $35,000 vehicle (P), but because you don't currently have the money to finance the entirety of the vehicle, you agree to pay $8,500 per year (A) for 7 years...

  • part b and c In class we derived a Fokker-Planck equation for the velocity distribution P(et)...

    part b and c In class we derived a Fokker-Planck equation for the velocity distribution P(et) starting from the assumption of small random changes in velocity at each time step f.(t) where f(t) is chosen from a distribution WU: ). Einstein's original approach to Brownian motion had a different starting point, focusing on position differences at each time step x(t + Δt)-x(t) + E(t) where £(t) is a random displacement chosen from some distribution W(E). Underlying this ap- proach is...

  • What an Executive Summary Is An executive summary is a specific type of document that does...

    What an Executive Summary Is An executive summary is a specific type of document that does two things: it summarizes a research article, and it offers recommendations as to how information from the article can be used. Some long reports can contain an executive summary section, as indicated in the Pearson handbook. Write a 2 pahe Executive Summary In business contexts, an executive summary is always written for a specific purpose: to explain the information in the article to a...

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