** 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

Basic Subject

Computer Science

- Programming Assignment Help
- Database Help
- Data Structure Assignment Help
- Operating Systems Assignment Help
- Computer Network Assignment Help
- UML Diagram Assignment Help
- IT Assignment Help
- Game Programming
- Computer Science Assignment Help
- Medical Science Assignment Help
- Social Science Assignment Help
- Information Systems

Engineering

- Biochemical and Biotechnology Help
- Chemical Engineering Assignment
- Statistics Assignment Help
- Civil Engineering Assignment Help
- Electrical, Electronics Help
- Mathematics, Computing Assignment Help
- Mechanical and Industrial Engg. Help
- Petroleum Engg. Assignment Help
- Biochemistry Assignment Help
- Cell Biology Assignment Help
- Arts and Architecture Help
- Silverlight Assignment Help