Error implementing Newton's Method

Tried implementing Newton's Method in MATLAB, but receiving this error regarding indexing. Not sure what this means or how to fix it.

Antworten (1)

Walter Roberson
Walter Roberson am 26 Aug. 2024

0 Stimmen

syms x
f = @(x) x^3 - 2*x^2 - 5;
df = diff(f,x)
df = 
class(df)
ans = 'sym'
Notice that the class of df is sym. df is a symbolic scalar. Attempting to invoke df(po) is an attempt to index the symbolic scalar df at the location indicated by po
What you need is
df = matlabFunction( diff(f, x) )

Produkte

Version

R2024a

Gefragt:

am 26 Aug. 2024

Beantwortet:

am 26 Aug. 2024

Community Treasure Hunt

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

Start Hunting!

Translated by