0% found this document useful (0 votes)
0 views5 pages

MatLab Lesson 1

This document is a lesson on MATLAB focusing on matrices and vectors. It covers creating matrices, performing operations like addition and transposition, and using functions such as 'max' and 'min'. The lesson also includes examples of variable naming and plotting functions.

Uploaded by

takkkie556
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)
0 views5 pages

MatLab Lesson 1

This document is a lesson on MATLAB focusing on matrices and vectors. It covers creating matrices, performing operations like addition and transposition, and using functions such as 'max' and 'min'. The lesson also includes examples of variable naming and plotting functions.

Uploaded by

takkkie556
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/ 5

MATLAB Lesson 1

% Matrices and Vectors


clc, clearvars

x = 1:10 % Create a 1X10 matrix

% Clear variable from memory whos % to check the details of x

clearvars

% Clear command Window, clc clears all the text from the Command Window, resulting in a clear
screen. After running clc, you cannot use the scroll bar in the Command Window to see
previously displayed text. x’ % x transpose

clc

% Naming variables with showing output

you = 25, me = 10

% Naming variables without showing output

you = 25; me = 10;

x= linspace(20,50) % ask MATLAB to draw 100 terms from 20 to 50


x= linspace(0,100,101) % as MATLAB to draw 101 terms from 0 to 100 matrix

A = [ 1 3 ; 2 -10] % returns a two by two matrix as follows

B = [ 1 3 ; 2 -10 ; 88 99] % returns a matrix as follows

y = [12 50 -8 -100] A + 2 % returns a matrix by adding 2 to every element.

y = [12, 50, -8, -100]

every element.

rows by 2 cols, it cannot


B= zeros(5)

B=zeros(2,8)

clc, clearvars

y = [12 50 -8 -100]

y.^2

X=eye(3) %returns a 3x3 matrix I

clc, clearvars

A = ones(3) % create a 3X3 matrix with all 1

A = ones(3, 1) % create a 3 rows by 1 col matrix with all 1


clc, clearvars

clc, clearvars A = [ 5 3 4.2; 5 9 88]

A = [ 5 3 4.2; 5 9 88]

A (2,3) % to call the value for matrix A for the 2nd row and the 3rd col

% Changing a value from the matrix

clc, clearvars

clc, clearvars A = [ 5 3 4.2; 5 9 88]

A = [ 5 3 4.2; 5 9 88] A (1,1)=100

nd
row

clc, clearvars

A = [ 5 3 4.2; 5 9 88]
nd
col
Exercise [MaxVal, I] = max(y) %return the index of max value

a) What is the maximum value of the follo

b) What is the minimum of the fu


c) At what x-value does the maximum y-
d) What is y(20.7)
x_maxval = x(I)

Answer
clc, clearvars

x=linspace(0,5); % to create 100 terms from 0 to 5

y= (-(x-3).^2) + 10 %

plot(x,y) % x,y clc, clearvars

x=linspace(0,5);

y= @(x) (-(x-3).^2) + 10

y(20.2)

max (y)

min(y)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy