Beruflich Dokumente
Kultur Dokumente
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));
= sin ( x ) - x . ^5;
= 1