MATLAB: How do i remove the last V= line as it’s not required

extra answer lineremove unwanted answer

function [ xvec ] = iteration(N);
x(1)=1 ;
for k=1:(N);
x(k +1)=(x(k)/2) + 3/x(k);
end
xvec=x;
disp('The elements x 0,x 1,. . .,x N, stored in xvec are:');
disp(xvec);
ezplot('y=x/2 + 3/x',[2 4]);
hold on
ezplot(('y=x'),[2 4]);
title('A fixed point');
fun=@(x)x^2-6;
xo=1;
xz=fzero(fun,1);
disp('The zero to xˆ2-6 is:');
disp(xz);
v=abs(xvec-sqrt(6));
disp('v =');
disp(v);
end
Result:
>> v=iteration(5)
The elements x 0,x 1,. . .,x N, stored in xvec are:
1.0000 3.5000 2.6071 2.4543 2.4495 2.4495
The zero to xˆ2-6 is:
2.4495
v =
1.4495 1.0505 0.1577 0.0048 0.0000 0.0000
v =
1.0000 3.5000 2.6071 2.4543 2.4495 2.4495

Best Answer

Use
v=iteration(5);
with the semi-colon at the end of the line.
Related Question