clear all; clc; clf;
% plot various functions
clear all
x = -3:.1:3;
y1 = 1+x;
y2 = 1+x+x.^2/2;
y3 = cos(x);
y4 = exp(x);
plot(x,y1,x,y2,x,y3,x,y4); grid on;
legend ('1+x','1+x+x.^2/2','cos(x)','exp(x)','location','northwest');
% newton's method
clear all;
x0 = 2.0;
% f(x)
f = @(x) x.^3-2*x+5;
% f'(x)
fp = @(x) 3*x.^2-2;
t = 1E-7;
ep = 1E-14;
max= 200;
for i = 1 : max
y = f(x0);
yp = fp(x0);
if (abs(yp < ep))
break;
end
x1 = x0 - y/yp;
if (abs(x1-x0)/abs(x1) < t)
fprintf('\nrun %d ----- x = %.4f\n', i, x1);
break;
end
x0 = x1;
end
% solve the general equation
syms y(x)
eqn = diff(y,x) == 5/6*y;
eqnp = dsolve( eqn );
pretty (eqn)
pretty (eqnp)
% matrix algebra
clear all;
A = [ 1 2 3; 2 3 4; 1 2 5];
dtm = det(A);
imt = inv(A);
[v,D] = eig(A);
disp('Matrix A = ');
disp(A);
fprintf('\nthe determinant of A is %.4f\n', dtm);
disp('Matrix inverse A = ');
disp(imt);
disp('the eigenvalues on the diagonal of a diagonal matrix ');
disp(D);
The ouput on the IDE should be
The graph should look like