フィルターのクリア

Why do I have an error on line 17 of the code? or there is another error

1 回表示 (過去 30 日間)
Freddy
Freddy 2023 年 11 月 30 日
編集済み: Torsten 2023 年 12 月 1 日
syms x
f=x.^8-7*x.^3 + 7;
d=diff(f);
fplot(f,[0 10]);
pause(1);
hold on;
lambda=1;
xo=1;
fxo=1;
x_value=[];
y_value=[];
for i=1:50
x_value=[x_value xo];
y_value=[y_value fxo];
xo=xo-lambda*d;
fxo=xo.^8-7*xo.^3+7; % Corrección aquí
plot(x_value,y_value,'*','linewidth',1);
pause(0.02)
end
Error using plot
Data must be numeric, datetime, duration, categorical, or an array convertible to double.
toc
  2 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 11 月 30 日
xo=xo-lambda*d;
What is this line suppossed to do?
xo and lambda are numbers, but d is an expression in the symbolic variable x.
Freddy
Freddy 2023 年 12 月 1 日
移動済み: Voss 2023 年 12 月 1 日
I try to capture the gradient descent method and that line iterates the values until the minimum is found.

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

採用された回答

Walter Roberson
Walter Roberson 2023 年 12 月 1 日
syms x
f=x.^8-7*x.^3 + 7;
d=diff(f);
d is a symbolic expression in x
xo=xo-lambda*d;
That symbolic expression in x is used. Note that you are not evaluating d at the current point, so the result is going to involve the symbolic variable x, so you will not be able to convert the result to numeric form.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by