Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.04 KB | None | 0 0
  1. clc;
  2. clear all;
  3. close all;
  4.  
  5. x=1.2;                                             %Setting the x value given in the notes. At which we are evalutating
  6. h=logspace(-16,-2, 1000);                          %Logarithmically producing the start and end values with even intervals.
  7. y=(0.5*h)*abs(-sin(x));                            %working out the second derivative of the function
  8.  
  9. f=zeros(1000);                                     %Creates a 1000x1000 zeros matrix
  10.  
  11. for i=1:1000                                       %for loop for 1000 itterations from i=1 to i=1000
  12.     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)
  13. end
  14.  
  15. loglog(h,f,'k',h,y,'r')                            %Producing a logatithmic plot of the
  16. xlabel('h')                                        %Labelling the x axis
  17. ylabel('Discretization errors')                    %labelling the y axis
  18. title('Round-off and discretization errors')       %titel for the graph
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement