Securing Higher Grades Costing Your Pocket? Book Your Assignment at The Lowest Price Now!

# How To Comment In Matlab File

## How To Comment In Matlab File

Matlab probability generating function

function root = modsecant(func,del,xr,acc,K,P,R)

%Firstly we evaluate the function at the first guess of the root and at

%a small pertubation, del, from the the first guess of the root.

fxr=feval(func,K,P,R,xr);

% xr at the pertubation is referred to as xrd

xrd=xr+del;

fxrdel=feval(func,K,P,R,xrd);

%Now we can evaluate a numerical estimate of the derivative

dfxr=(fxrdel-fxr)/del;

% We will use a 'While' loop to loop through our guesses at the root of the

% function. Whilst the value of the function evaluated at the root is

% greater than the accuracy we have specified, 'acc' then we keep looping.

% We are also going to count the number of loops it takes to find the root

% in the variable, 'LoopNum'

i=0;

while (abs(fxr)>acc)

%Evaluate the new guess at the root using the Newton-Raphson formula

xr=xr-fxr/dfxr;

%The values of the function at the new guess and at a small pertubation

%from the new guess can then be evaluated

fxr=feval(func,K,P,R,xr);

xrd=xr+del;

fxrdel=feval(func,K,P,R,xrd);

%Now we can evaluate a numerical estimate of the derivative

dfxr=(fxrdel-fxr)/del;

% After each attempt we increment our number of guesses at the root by one.

% Note: This has no effect at all on the routine. It is just so we can

% plot the guesses it takes before we arrive at the solution.

matlab price bonds with default risk mfile

i=i+1;

LoopNum(i)=i;

Storage_xr(i)=xr;

Storage_fxr(i)=fxr;

end

subplot(1,2,1)

plot(LoopNum,Storage_xr)

xlabel('Iteration number')

ylabel('Guess at the root, t(m)')

subplot(1,2,2)

plot(LoopNum,Storage_fxr)

xlabel('Iteration number')

ylabel('Value of function at current guess of the root')

root=xr;

MATLAB Assignment help | Programming Assignment help | Online Tutoring

Assignment Help Features
Assignment Help Services
• Assignment Help
• Homework Help
• Writing Help
• Academic Writing Assistance
• Editing Services
• Plagiarism Checker Online