Sie sind auf Seite 1von 2

function y = Q1A ()

x = linspace ( -3 ,3 ,1000);
alpha = -2;
% g = tan (4 . * x ) + ( x + alpha ) . ^3;
g = sin (4 . * x ) + (( x + alpha ) . ^3) . * cos (4 . * x );
plot (x ,g , r );
grid on
end
function y = Q1C ()
x = linspace (0 ,1 ,1000);
alpha = -2;
g = sin (4 . * x ) + (( x + x ) . ^3) . * cos (4 . * x );
plot (x ,g , r );
grid on
end
function myplot ( f )
x = linspace ( -2 * pi ,2 * pi ,100000);
% x = linspace ( -2 * pi ,2 * pi ,1000);
y = f ( x );
plot (x ,y , r );
grid on
end
function nr (f , df ,a ,n , tol )
% f is the function , df is its derivative ,
% a is initial guess , n is number of iteration
% tol is tolerance .
initial = a ;
error = Inf ;
for i =1 : n
b = a - f ( a )/ df ( a );
error = abs ( b - a ); % taking relative error
if tol >= error
break
end
a = b;
end
% fprintf ( | b : % . 12 f | \ n | steps : % i | \ n | error : % . 12 f | \ n ,b ,i , error );
% latex output
% fprintf ( % . 2 f & % . 12 f &
% % i & % d \\\\ \\ hline \n , initial ,b ,i , error );
end
function honr ( x )
s = size ( x );
for i = 1 : s (1)
nr ( @Q1E , @Q1ED , x (i ,1) ,40 ,10^ -12);
end
end
function hof ( x ) % higher order function
s = size ( x );

for i = 1 : s (1)
a = ( x (i ,1));
b = ( x (i ,2));

mb = myBisection ( @Q1E ,a ,b ,10^ -12);


% fprintf ( % f & % f & % . 12 f
% & % i \\\\ \ n ,a ,b , mb (1) , mb (2)); % latex output
end
end
function honr ( x )
s = size ( x );
for i = 1 : s (1)
nr ( @Q1E , @Q1ED , x (i ,1) ,40 ,10^ -12);
end
end
function y = Q1E ( x )
% y = 5 . * cos ( x ) - x ;
%2
% y
%3
% y
%4
% y
%5
% y
% y
y =

= sin ( x ) - x . ^5;
= 1

- ((( x + 1) . ^2) . /2) . * cos ( x );

= 1 - / sin ( x ) - 10 * e . ^( -( x . ^2) . /2);


= 1 - sin ( x ) - 10 . * ( exp ( - x . ^2) . /2);
= ( x + 1) . ^5;
-( x . ^3) . /40 + ( x . ^2) . * (3/10) - ( x ) . * (11/10) + 11/10;

% y = sin (4 . * x ) + (( x - 2 ) . ^3) . * cos (4 . * x );


function y = Q1ED ( x )
% % y = 5 . * cos ( x ) - x ;
% y = -5 . * sin ( x ) - 1;
% % y = sin ( x ) - x . ^5;
% y = cos ( x ) - 5 . * x . ^4;
% % y = 1 - ((( x + 1) . ^2) . /2) . * cos ( x );
% y = -( x + 1) . * cos ( x ) + ((( x + 1) . ^2) . /2) . * sin ( x );
% % y = 1 - sin ( x ) - 10 * e . ^( -( x . ^2) . /2);
% % y = 1 - sin ( x ) - 10 . * ( exp ( - x . ^2) . /2);
% y = 10 . * x . * exp ( -0 . 5 . * x . ^2) - cos ( x );
% % y = ( x + 1) . ^5;
% % y = 5 . * x . ^4 + 20 . * x . ^3 + 30 . * x . ^2 + 20 . * x + 5 % expanded
% y = 5 . * ( x + 1) . ^4;
% y = -( x . ^3) . /40 + ( x . ^2) . /10 - ( x ) . /10 + 11 . /10;
% y = -3/40 . * x . ^2 + 3/5 . * x - 11/10;
% y = ( -4 . * (x -2) . ^3) . * sin (4 . * x ) + (3 . * (x -2) . ^2) . * cos (4 . * x );

Das könnte Ihnen auch gefallen