fprintf(' initial guess: %23.15e\n',Xo)
for the other print a string whith the column titles correctly positioned before printing the table.
CB
Okay, so I've completed a Matlab assignment but need to refine a few points. I'd like to add a caption next to Xo stating that it is the 'initial estimate'.
Also I need to label the columns which appear as output but don't know how. Can anyone help please?
Here's my code:
% function takes value for Xo
% enters Xo into Newton-Rhapson formula
%Calculates Xnew and determines difference(accuracy)
%Adjusts value of Xold to value of Xnew
%Repeats process until satisfactory level of accuracy is achieved
function[y]= Newton(Xo, epsilon)
fprintf('%23.15e\n',Xo)
format long;
count=0;
acc=epsilon +1;
Xold=Xo;
while acc>=epsilon;
count= count +1;
Xnew= Xold-(f)/(fdash);
acc = abs(Xnew-Xold);
fprintf('%23.15e %23.15e\n',Xnew,acc)
Xold= Xnew;
if count >100;
error('No convergence after 100 iterations')
end
end
y= Xnew
%registered value for Xo is entered into function
%value is returned
function[f]= f(Xo)
w= Xold-exp(-(Xold^2));
f= w;
%registered value for Xo is entered
%into derivative of function
%value is returned
function[fdash]= fdash(Xo)
z= 1+(2*Xold*exp(-(Xold^2)))
fdash=z;