Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc;
- clear all;
- close all;
- x=1.2; %Setting the x value given in the notes. At which we are evalutating
- h=logspace(-16,-2, 1000); %Logarithmically producing the start and end values with even intervals.
- y=(0.5*h)*abs(-sin(x)); %working out the second derivative of the function
- f=zeros(1000); %Creates a 1000x1000 zeros matrix
- for i=1:1000 %for loop for 1000 itterations from i=1 to i=1000
- f(i)=abs(((sin(x+h(i))-sin(x))/h(i))-cos(x)); %This is the expression that was given in the lecture notes. Every itteration the value of h will go up by 1. (1 till 1000)
- end
- loglog(h,f,'k',h,y,'r') %Producing a logatithmic plot of the
- xlabel('h') %Labelling the x axis
- ylabel('Discretization errors') %labelling the y axis
- title('Round-off and discretization errors') %titel for the graph
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement