






















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!























Lecture 1a Introduction to MATLAB: Some Basics Ref: Appendix B, MATLAB Tutorial
% Script(Ex1p): Plots the function f(x) = sin(2pix) % on the interval [0,1] using 11 equally-spaced points.
% Define x-points. n = 11; x = zeros(1,n); x = [0, .1, .2, .3, .4, .5, .6, .7,... .8, .9, 1];
% Evaluate y(x) = sin(2pix) for these x-points. y = zeros(1,n); for i = 1:n y(i) = sin(2pix(i)); end
% Plot sin(2pix) vs. x on [0,1]. plot(x,y);
% Script (Ex1vp): plots and prints the function f(x) = sin(2pix) % on the interval [0,1] using 11 equally-spaced points.
% Define x- and y-points. n = 11; x = linspace(0,1,n); y = zeros(1,n); y = sin(2pix);
% Print sin(2pix) vs. x on the interval [0,1]. disp(' x sin(2pix)') for i = 1:n disp(sprintf(' %3.1f %6.4f',x(i),y(i))); end
% Plot sin(2pix) vs. x on the interval [0,1]. plot(x,y);
>> ex1pvp x sin(2pix) 0.0 0. 0.1 0. 0.2 0. 0.3 0. 0.4 0. 0.5 0. 0.6 -0. 0.7 -0. 0.8 -0. 0.9 -0. 1.0 -0. >>
2.1 3. 4.12 1. 7.1 5
^
A
>> A = zeros(3,2); >> A(1,1) = 2.1; >> A(1,2) = 3.23; >> A(2,1) = 4.12; >> A(2,2) = 1.893; >> A(3,1) = 7.1; >> A(3,2) = 5.; >> A A = 2.1000 3. 4.1200 1. 7.1000 5. >>
In the next few Viewgraphs, we examine some standard operations with matrices that are allowed in MATLAB. +, -, , ., ^, .^, /, ./, , .\
2 3 2 22 23 2 3 32 33 3
2 3
M M M
N N N NM
11 1 1 1 1 1
1
2 1 3 2 4 2 4 1
A
B
C A B
>> A = [2, 1; 3, 2; 1, 4]; >> B = [4, 2; 4, 1]; >> C = A + B ??? Error using ==> plus Matrix dimensions must agree. >>