How do I do this question?

1 vue (au cours des 30 derniers jours)
Chad
Chad le 31 Oct 2014
Commenté : Star Strider le 31 Oct 2014
I have to finish this and don't know how to exactly do it: The algorithm is very simple. We want to find x= ∜N
Make an initial guess for x: Est. See how close you are: Error = abs(Est4 – N) If the Error is too big, update the estimate as follows:
Est=Est- (Est^4-N)/(4*Est^3 )
Recalculate the Error using the new estimate Repeat until the value of Error is small enough.
Write a MATLAB script that does the following:
Prompts the user for the Number, N, to find the 4th root of Sets the initial guess to 1 Uses the algorithm describe above to repeatedly update the estimate until the value of Error does not exceed 0.0001. Saves all the values for Est in a vector Outputs the following:
The final value of the estimate for the 4th root of N. Use 4 decimal places. A count of how many iterations were required through the loop A plot with all the values for Est4
This is what I have so far:
N = input ('Enter the number: ');
est = 1;
error = abs(est.^4-N);
while error > .0001;
est = (est-((est.^4-N)/(4*est.^3)));
error = abs(est.^4-N);
end

Réponse acceptée

Star Strider
Star Strider le 31 Oct 2014
Your code works as far as it goes.
You still need to:
  1. Initialise a counter to zero before the loop and update it within the loop,
  2. Use the counter value at each iteration to subscript ‘Outputs’ after it is computed and assign the current value of ‘est’ to it,
  3. For the 4 decimal place precision, I would use the round function with appropriate multiplications and divisions to get the correct format, although you could also use sprintf, depending on what functions you are allowed to use,
  4. Then the plot of ‘Outputs’ is straightforward.
  2 commentaires
Chad
Chad le 31 Oct 2014
Thank you so much, I can't believe that it was that easy, I was going over this again and again and had everything but the count and couldn't figure out why it still was not working lol. But thank you again!!
Star Strider
Star Strider le 31 Oct 2014
My pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by