Why it says undefined variable x2

function [x2] = secant(f, x0, x1)
while true
x2 =f(x1)*(x2-x0)/f(x0)+x1;
if x1 == x2
return;
end
x0 = x1;
x1 = x2;
end
end

답변 (1개)

James Tursa
James Tursa 2018년 9월 26일

0 개 추천

You have x2 appearing on the right hand side of your first assignment, before it has been defined.

댓글 수: 3

Dandan Lv
Dandan Lv 2018년 9월 26일
thank you so much
Hazel
Hazel 2023년 9월 9일
편집: Hazel 2023년 9월 9일
Hello @Dandan Lv, have you figured out this x2 equation that does not contain x2 on the RHS?
Torsten
Torsten 2023년 9월 9일
Set n = 2 in the first formula on

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

질문:

2018년 9월 26일

댓글:

2023년 9월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by