We want to solve x^3-4x+1=0 using Newton's method.
a) Graph f(x) = x^3-4x+1. Then choose 3 starting values to find the 3 solutions using Newton's method
b) Write a Matlab program of Newton's method to find the 3 solutions by question
c) Establish the table of errors En+1/En. What is the order of convergence for each solution ?

6 件のコメント

Steven Lord
Steven Lord 2022 年 5 月 14 日
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
Konian Jean Philippe Lionnel Moro
Konian Jean Philippe Lionnel Moro 2022 年 5 月 14 日
編集済み: Walter Roberson 2022 年 5 月 15 日
clc;
close all;
clear all;
syms x;
f(x)= x^3-4*x+10; %Enter the Function here
g=diff(f); %The Derivative of the Function
n=input('Enter the number of decimal places:');
epsilon = 1e-10
x0 = input('Enter the intial approximation:');
for i=1:100
f0=vpa(subs(f,x,x0)); %Calculating the value of function at x0
f0_der=vpa(subs(g,x,x0)); %Calculating the value of function derivative at x0
y=x0-f0/f0_der; % The Formula
err=abs(y-x0);
if err<epsilon %checking the amount of error at each iteration
break
end
x0=y;
end
Walter Roberson
Walter Roberson 2022 年 5 月 14 日
okay, what is the question?
Sam Chak
Sam Chak 2022 年 5 月 14 日
Not sure. Maybe @Konian Jean Philippe Lionnel Moro wants to display the solution
y
or to find the other two roots
Konian Jean Philippe Lionnel Moro
Konian Jean Philippe Lionnel Moro 2022 年 5 月 14 日
@Walter Roberson Write a Matlab program of Newton's method to find the 3 solutions per question
Walter Roberson
Walter Roberson 2022 年 5 月 14 日
You posted code. What is the difference between the result of the code you posted, compared to what you want? Are you getting an error message?

サインインしてコメントする。

 採用された回答

Sam Chak
Sam Chak 2022 年 5 月 14 日
編集済み: Sam Chak 2022 年 5 月 14 日

2 投票

Please find out relevant info about Newton-Raphson method here, and see if helps you in writing the code and solving the problems.
Let us know your experience with MATLAB...

その他の回答 (1 件)

Konian Jean Philippe Lionnel Moro
Konian Jean Philippe Lionnel Moro 2022 年 5 月 14 日

0 投票

@Walter Roberson Yes, "Enter the number of decimal places"

1 件のコメント

Walter Roberson
Walter Roberson 2022 年 5 月 15 日
I ran your code exactly as posted, using various inputs. It appears to execute without error for me, for any numeric scalar n and numeric scalar initial guess.
I do see that in the code, you do not use the value of n (decimal places) that you enter, but that does not lead to any error messages.
You should probably be calculating epsion in terms of n, instead of using a fixed epsilon.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by