Help with building an Iteration function

조회 수: 5 (최근 30일)
Chrissie
Chrissie 2014년 12월 2일
댓글: Chrissie 2014년 12월 2일
function [out] = iteration(N)
if N<1
error('Input must be >0')
end
x(1)=4;
for k=1:N
x(k+1)=1+(0.5*sin(k)); %#ok<AGROW>
end
disp('The elements stored in x are:')
disp(x)
fun=@(x)1+(0.5*sin(x));
xz=fzero(fun,2);
disp('The zero given by xz is:')
disp(xz)
out=abs(xz-x);
disp('v=')
disp(out)
Hi, Above is my code so far however it doesn't work for the fzero part and shows v as NaN and also for the last part, I have no idea what to do
Any suggestions are appreciated :)
  댓글 수: 2
Star Strider
Star Strider 2014년 12월 2일
What needs more input arguments? It’s not at all clear.
Chrissie
Chrissie 2014년 12월 2일
I do apologise for being unclear, but I've figured out what I was doing wrong there, I've edited the question for the second part

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

답변 (1개)

Thorsten
Thorsten 2014년 12월 2일
You have to call your function with one input, e.g.
iteration(20)
  댓글 수: 1
Chrissie
Chrissie 2014년 12월 2일
I eventually figured that part out but thankyou! However now theres another issue, Ive edited my question for it :)

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

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by