0% found this document useful (0 votes)
40 views

Numerical Analysis Lab One

This document contains two numerical analysis lab summaries: 1) The first lab covers using MATLAB as a calculator, plotting vectors, formatting, and help commands. 2) The second lab discusses plotting multiple vectors, formatting plots, vectors and matrix operations like transposes, indexing, deleting rows and columns, and common matrix functions like zeros, ones, eye, and random matrices.

Uploaded by

Mah Rukh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Numerical Analysis Lab One

This document contains two numerical analysis lab summaries: 1) The first lab covers using MATLAB as a calculator, plotting vectors, formatting, and help commands. 2) The second lab discusses plotting multiple vectors, formatting plots, vectors and matrix operations like transposes, indexing, deleting rows and columns, and common matrix functions like zeros, ones, eye, and random matrices.

Uploaded by

Mah Rukh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

NUMERICAL ANALYSIS LAB ONE

%-- 9/15/2023 8:34 AM --%


2+3
x=2+3
2+3*6
y=3
4*y
5*x
5y
5*y
1/3
format long
z=1/3
help format
format
1/3
clc
clear all
hep clear
help clearhelp clear
help clear
help elf
help elfun
help specfun
a=7;b=4
c=9;
a=8;b=5;
cls
clc
a=7, b=cos(a), c= sin(a)
who
help Command
lookfor inverse
clc
help pow
help elfun
y = exp(sqrt(a))- 2*b + sin(c)
a=7;b=2;c=3
y = exp(sqrt(a))- 2*b + sin(c)
pi
inf
Inf
NaN
1/0
0/0
0/1
clc
% comments
% plotting in matlab
%plotting two vectors in MATLAB
x = [1 3 5 7 9]
y= [2 4 6 8 10];
plot(x,y)
plot(x)
plot(y)
plot(x,y)
x = 0:2*pi
x=0:0.1:2*pi
y=sin(2*x)
plot(y)
plot(x,y)
xlabel('THE X VALUES')
y2=2*cos(3*x)
y3=3*sin(cos(x))
plot(x,y,x,y2,x,y3)
legend('Funct One', 'Funct Two', 'Funct Three')
help plot
plot(x,y,'ro:')
x = -pi:pi/10:pi;
y = tan(sin(x)) - sin(tan(x));
plot(x,y,'--rs','LineWidth',2,
'MarkerEdgeColor','k',
'MarkerFaceColor','g',
'MarkerSize',10)
x = -pi:pi/10:pi; y = tan(sin(x)) - sin(tan(x));
plot(x,y,'--rs','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',10)

NUMERICAL ANALYSIS LAB TWO


- How to use matlab as a calculator
- Plotting two vectors with same dimensions
- Formatting
- Help keyword
- Command history and workspace
-

% NUMERICAL ANALYSIS LAB TWO


x = [4 5 7 9]; y = [5 8 13 15];
plot(x,y)
help plot
xlabel("Values of x")
ylabel("Values of y")
title('Plotting x against y")
title("Plotting x against y")
legend('show')
x= -1*pi : pi
y1 = sin(x)
y2 = 2*cos(x)
y3 = 3 * sin(2*x)
plot(x,y1,x,y2,x,y3)
xlabel("Pi values")
ylabel("Y Axis")
legend("y1","y2","y3")
plot(x,y1,'b.-', 'LineWidth',2,x,y2,'g+:','LineWidth',3,x,y3, 'rp--', 'LineWidth',4)
plot(x,y1,'b.-',x,y2,'g+:',x,y3, 'rp--')
p = plot(x,y1,'b.-',x,y2,'g+:',x,y3, 'rp--')
p(1).LineWidth = 2;
legend("y1","y2","y3")
p(2).LineWidth = 2.5
p(3).LineWidth = 3
%vectors and Matrices operations in matlab
%arrays of numbers
%-one col/row -- vector
% Matrix A(mxn)
% Row Vector 1xn
% Col Vector mx1
x = [2 3 4 5]
y = [2 3 4 5]
v = [1 3 5 7 9]
v(3)
v(3) = 6
u = [1; 3;5;7]
u(3)
u(3)=8
u'
UTrans = u'
VTrans = v'
VTrans(3:end)
VTrans(:)
a=[1 3 5; 7 9 11; 13 15 17]
a(5)
a(2,2)
a(1,3)
%a(r,c)
a(3,2) = 9
a(2,:)
clc
a(:,2)
%del row/col
a(:,2) =[]
a(1,:) = []
b = [2 4 6;8 10 12; 13 15 16]
c = b([2,3],[1,2])
%a([r1,r2,..],[c1,c2,...])
c = b([2,3],[1,2,3])
d = b([1 2],[2 3])
BTrans = b'
e = BTrans([2 1 3],:)
e(:)
diary
clc
a = [1 3 5; 7 9 11; 13 15 15]
b=a(3,:) = []
a(3,:) = []
a(:,3) = []
size(a)
[m,n] = size(a)
b = [1,3,5; ...]
2 4 6; ...
5 7 9]
zeros(3_
zeros(3)
zeros(3,2)
eye(3)
ones(3)
ones(2,3)
eye(2,3)
diag(b)
b
rand(3)
magic(3)
help magic
help elmat
C = [1 2; 3 4]
D = [C zeros(2); ones(2) eye(2)]
A = rand(3)
B = rand(3)
C = a*b
C=A*B
D = A.*B
% .* -- element by element multiplication
% * -- normal multiplication
E=A^2
F = A .^ 2
G=A+B
H = A .+B
2*A
inv(A), %inverse of a
b = rand(3,1)
b = b'
X = inv(A) * b
b = rand(3,1)
X = inv(A) * b
x = A\b
x = b/A
det(A)
rank(A)
help rank
norm(A)
help norm
%norm tells whether the system has a solution or not

You might also like