What does the following code do?

조회 수: 1 (최근 30일)
daniel
daniel 2022년 12월 26일
답변: Voss 2022년 12월 26일
clear all
close all
clc
x= input('Enter initial condition: ')
eps= input('Enter accuracy : ')
Nmax= 1e5
for N=1:Nmax
f= 2*x+exp(x/pi)+sin(pi*x)-20
df= 2+(1/pi)*exp(x/pi)+pi*cos(pi*x)
newx= x-f/df
if abs(newx-x)<=eps
disp(['The solotion is: ',num2str(newx)])
disp(['The number of attempts is: ',num2str(N)])
break
end
x=newx
end
if N==Nmax
disp('There is no solution for the given conditions!')
end
At least one END is missing. The statement beginning here does not have a matching end.
  댓글 수: 3
the cyclist
the cyclist 2022년 12월 26일
Please read this guide about how to ask a good question, and edit your question to improve it.
What your code will do is give the error message you see in red above (after I formatted your code, and ran it here).
daniel
daniel 2022년 12월 26일
Sorry I fixed the code

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

답변 (1개)

Voss
Voss 2022년 12월 26일

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by