SlideShare a Scribd company logo
1 of 15
Selective codes
>> x=[0:2:18];
y= [0, 0.33, 4.13, 6.29, 6.85, 11.19, 13.19, 13.96, 16.33, 18.17];
plot(x,y)
title('Laboratory Experiment 1')
xlabel('Time, sec')
ylabel('Distance, ft')
grid on
------------------------------------
>> x = 0:pi/100:2*pi;
y1 = cos (x*4) ;
plot (x,y1)
hold on
y2 = sin(x) ;
plot(x,y2)
-----------------------------------
x = 0:pi/100:2*pi;
yl = cos(x*4);
y2 = sin(x);
plot(x,y1,x,y2)
y1 = cos(x)*2;
y2 = cos(x)*3;
y3 = cos(x)*4;
y4 = cos(x)*5;
plot(x, y1, x, y2, x, y3, x, y4)
----------------------------------
x = [1:10];
y= [58.5, 63.8, 64.2, 67.3, 71.5, 88.3,90.1, 90.6, 89.5, 90.4];
plot(x,y,':ok')
----------------------------------------
x = [1:10];
y= [58.5, 63.8, 64.2, 67.3, 71.5, 88.3,90.1, 90.6, 89.5, 90.4];
plot(x,y,':ok',x,y*2,'--xr',x,y/2,'-b')
axis([0,11,0,200])
legend('line 1', 'line 2', 'line3')
text(1,100,'Label plots with the text command')
----------------------------------------------------------
x=0:pi/100:2*pi;
>> y=sin(x);
>> plot(x,y)
>> y=abs(sin(x));
>> plot(x,y)
-----------------------------------
x=0:pi/20:2*pi;
subplot(2,1,1)
plot(x,sin(x))
subplot(2,1,2)
plot(x,sin(2*x))
xlabel('My x label'), ylabel('My y label')
title('Example graph for Chapter 5')
----------------------------
x=0:pi/100:pi;
y=sin(x);
polar(x,y);
>> title('Siva')
---------------------------
x = 0:0.5:50 ;
y = 5*x.^2 ;
subplot (2 ,2 , 1)
plot (x ,y)
title ( ' Polynomial - linear/ linear' )
ylabel ( 'y') , grid
subplot (2 ,2 ,2)
semilogx (x ,y)
title ( ' Polynomial - log/ linear')
ylabel ( ' y') , grid
subplot (2 ,2 , 3)
semilogy (x ,y)
title ( ' Polynomial - linear/log' )
xlabel('x') , ylabel('y') , grid
subplot (2 ,2 ,4)
loglog (x,y)
title ( ' Polynomial - log/ log' )
xlabel('x') , ylabel('y') , grid
clear, clc
x=[1,2,5,4,8];
y=[x;1:5];
subplot(2,2,1)
bar(x),title('A bargraph of vector x')
subplot(2,2,2)
bar(y),title('A bargraph of matrix y')
subplot(2,2,3)
bar3(y),title('A three dimensional bargraph')
subplot(2,2,4)
pie(x),title('A pie chart of x')
---------------------------------
x = linspace (0,10*pi,1000) ;
y = cos (x) ;
z = sin(x) ;
plot3 (x,y,z)
grid
xlabel('angle' ) , ylabel(' cos (x) ')
zlabel(' sin (x) ') , title('A Spring')
-------------------------------------
z = [1,2,3,4,5,6,7,8,9,10;
2,4,6,8,10,12,14,16,18,20
3,4,5,6,7,8,9,10,11,12] ;
mesh(z)
xlabel('x-axis')
ylabel ('y-axis' )
zlabel( 'z-axis' )
-------------------------------
z = [1,2,3,4,5,6,7,8,9,10;
2,4,6,8,10,12,14,16,18,20
3,4,5,6,7,8,9,10,11,12];
x = linspace(1,50,10);
y = linspace(500,1000,3);
mesh(z)
xlabel('x-axis')
ylabel('y-axis')
zlabe1('z-axis')
-------------------------------
x= [-2:0.2:2];
y= [-2:0.2:2];
[X,Y] = meshgrid(x,y);
Z = X.*exp(-X.^2 - Y.^2);
subplot(2,2,1)
mesh(X,Y,Z)
title('Mesh Plot'), xlabel('x-axis'), ylabel('y-axis'), zlabel('z-axis')
subplot(2,2,2)
surf(X,Y,Z)
title('Surface Plot'), xlabel('x-axis'), ylabel('y-axis'), zlabel('z-axis')
subplot(2,2,3)
contour(X,Y,Z)
xlabel('x-axis'), ylabel('y-axis'), title('Contour Plot')
subplot(2,2,4)
surfc(X,Y,Z)
xlabel('x-axis'), ylabel('y-axis')
title('Combination Surface and Contour Plot')
------------------------------------------
[x,y,z] = peaks;
subplot(2,2,1)
pcolor(x,y,z)
subplot(2,2,2)
pcolor(x,y,z)
shading interp
subplot(2,2,3)
pcolor(x,y,z)
shading interp
hold on
contour(x,y,z,20,'k')
subplot(2,2,4)
contour(x,y,z)
function results=f(x)
%This function converts seconds
%to minutes
results = x./60;
------------------------
function output=g (x,y)
% This function multiplies x and y together
% x and y must be the same size matrices
a = x.*y;
output=a;
------------------------
function [dist, vel, accel] = motion (t)
% This function calculates the distance, velocity and acceleration
% for a given value of t
accel = 0.5 .*t;
val = accel .* t;
dist = vel.*t;
------------------------------
function[]=star( )
theta = pi/2:0.8*pi:4.8*pi;
r=ones(1,6);
polar(theta,r)
-------------------------------
disp('Hi There');
disp('I"m your Matlab program');
name=input('Who are you? (Enter your name in single quotes) ');
disp(['Hi ',name]);
answer=input('Don"t you just love computers?')
disp([answer,'?']);
disp('Computers are very useful');
disp('You"ll use them a lot in college!!');
disp('Good luck with your studies')
pause(2);
disp('Bye bye')
------------------------------
fprintf('Good golly Molly, there are %8.2f cows in the barn',A)
--------------------------------
fprintf('5 times %3.0f is %3.0f n' ,my table)
----------------------------------
% An example of a script file
% that creates a table of degrees to radians
degreestart=input('What starting number of degrees would you like?')
degreefinal = input('What final value of degrees would you like?')
incr=input('What table increment would you like?');
degree=degreestart:incr:degreefinal;
radian=degree*pi/180;
table=[degree;radian];
disp('A table of degrees to radians');
fprintf(' %4.2f %6.4f n',table)
----------------------------------
plot(sin(Iinspace(0,4*pi,100)))
[xVaIs,yVaIs]=ginput(3)
[xVaIs,yVaIs]=ginput(1)
--------------------------
xVals=Iinspace(0,pi,300)
plot(xVals, exp(-sin(xVals))
[xMin,yMin]=ginput(1)
---------------------
x = [ 1, 2, 3, 4, 5];
y= [-2, 0, 2, 4, 6]:
z = [ 8, 8, 8, 8, 8];
z>x & z>y
--------------------------
%Define a vector of mph values
mph = 0:10:100;
%Convert mph to ft/s
fps = mph*5280/3600;
%Combine the mph and ft/s vectors into a matrix
table = [mph;fps]
%Create a table title
disp('Velocity Conversion Table')
%Create column headings
disp('mph f/s')
%Display the table
fprintf('%8.0f %8.2f n',table)
-----------------------
%Define a vector of heights
height = [63,67,65,72,69/78,75]
%Use the find command to determine which are greater than 66
accept = find(height>=66 )
-----------------------------------
%Define a vector of heights
height = [63,67,65,72,69,78,75];
%Use the find command to determine which
%are greater than 66
accept = find(height>=66 )A
height(accept);
%Use the find command to determine which
%are less than 66
decline=find(height<66);
%Send your results to the command window
disp('The following candidates meet the height requirement');
fprintf('Candidate # %4.0f is %4.0f inches tall n', [accept;height(accept)])
--------------------------------------
%Create a 7x2 matrix of applicant height and age information
applicants = [63,18:67,19:65,18;72,20;69,36;78,34;75,12]
%Use the find command to determine which applicants are eligible
pass=find(applicants(:,1)>=66 & applicants(:,2)>=18 & applicants(:,2) < 35)
%Use fprintf to create a table of results
%First group the results into a table
results = [pass,applicants(pass,1),applicants(pass,2)]';
fprintf('Applicant # %4.0f is %4.0f inches tall and %4.0f years oldn',results)
-------------------------------------
temp = [95.3, 100.2, 98.6; 97.4,99.2, 98.9; 100.1,99.3, 97];
element=find (temp>98.6)
------------------------------------------------------------
temp = [95.3, 100.2, 98.6; 97.4,99.2, 98.9; 100.1,99.3, 97];
[row,col]=find(temp>98.6);
fprintf('Patient%3.0f at station%3.0f had a temp of%6.1f n', [row,col,temp(element)] ’)
----------------------------------------
%Define a vector of x values
x=[1,2,3; 10, 5,1; 12,3,2;8, 3,1];
%Find the index munbers of the values in x >9
element = find(x>9);
%Use the index numbers to find the x values
%greater than 9 by plugging them into x
values = x(element) ;
% Create an output table
disp('Elements greater than 9')
disp('Element # Value')
fprintf('%8.0f %3.0f n' , [element' ;values'])
-----------------------------
count =0
G= [30 , 55 , 10]
if G<50
count=count+1
disp (G)
end
-----------------------------
x=input('To calculate a natural log, enter a value for x: ')
if x >0
y = log(x)
else
disp('The input to the log function must be positive')
end
----------------------------
disp('Are you eligible to drive?’)
age=input('Enter your age:')
if age <16
disp(’Sorry — You"ll have to wait')
elseif age<18
disp('You may have a youth license')
elseif age<70
disp('You may have a standard license')
else
disp('Drivers over 70 require a special license')
end
--------------------------------
city = input('Enter the name of a city in single quotes: ')
switch city
case 'Boston'
disp('$345')
case 'Denver'
disp('$150')
case 'Honolulu'
disp('Stay home and study')
otherwise
disp('Not on file')
end
--------------------------------
city = menu('Select a city from the menu: ','Boston','Denver','Honolulu')
switch city
case 1
disp(''$345')
case 2
disp('$150')
case 3
disp('Stay home and study')
end
----------------------------
scores = [76,45,98,97];
count = 0;
for k=1:length(scores)
if scores(k)>90
count: = count + 1;
end
end
disp(count)
------------------------------
scores = [76,45,98,97];
count = 0;
k=0;
while k<4
k=k+1;
if scores(k)>90
count = count + 1;
end
end
disp(count)
----------------------------
n=0;
while(n<10)
n=n+1;
a=input('Enter a value greater than 0:');
if(a<=0)
disp('You must enter a positive number ’)
disp(' This program will terminate')
break
end
disp('The natural log of that number is')
disp(log(a))
end
------------------------------
n=0;
while(n<10)
n=n+1;
a=input('Enter a value greater than 0:');
if(a<=0)
disp('You must enter a positive number ')
disp(' Try again')
continue
end
disp('The natural log of that number is')
disp(log(a))
end
----------------------------
clear, clc
A=ones(200); %Creates a 200 x 200 matrix of ones
t0=clock;
B=A*pi;
time = etime(clock, t0)
----------------------------
%Create a 7x2 matrix of applicant height and age information
student=[71,62;53,41;62,74;50,91;42,39];
%Find the index munbers of the values in student >50
pass = find(student(:,1)>=50 & student(:,2)>=50);
fail = find(student(:,1)<=50 & student(:,2)<=50);
reseat= find(student(:,1)<=50 & student(:,2)>=50| student(:,1)>=50 & student(:,2)<=50);
%Use fprintf to create a table of results
result1 = [pass]
fprintf('Student # %4.0f passed n',result1)
result2 = [fail]
fprintf('Student # %4.0f fail n',result2)
result3 = [reseat]
fprintf('Student # %4.0f reseat n',result3)

More Related Content

What's hot

Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Suyeol Jeon
 
The Ring programming language version 1.5.2 book - Part 66 of 181
The Ring programming language version 1.5.2 book - Part 66 of 181The Ring programming language version 1.5.2 book - Part 66 of 181
The Ring programming language version 1.5.2 book - Part 66 of 181Mahmoud Samir Fayed
 
Send + More = Money – Let’s mash 2 monads to solve a simple CSP
Send + More = Money – Let’s mash 2 monads to solve a simple CSPSend + More = Money – Let’s mash 2 monads to solve a simple CSP
Send + More = Money – Let’s mash 2 monads to solve a simple CSPFilippo Vitale
 
The Ring programming language version 1.5.2 book - Part 29 of 181
The Ring programming language version 1.5.2 book - Part 29 of 181The Ring programming language version 1.5.2 book - Part 29 of 181
The Ring programming language version 1.5.2 book - Part 29 of 181Mahmoud Samir Fayed
 
PyTrening 2.0 # 15 Okienka GUI
PyTrening 2.0 # 15 Okienka GUIPyTrening 2.0 # 15 Okienka GUI
PyTrening 2.0 # 15 Okienka GUIMoniaJ
 
Ruby is Awesome
Ruby is AwesomeRuby is Awesome
Ruby is AwesomeAstrails
 
The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210Mahmoud Samir Fayed
 
Effector: we need to go deeper
Effector: we need to go deeperEffector: we need to go deeper
Effector: we need to go deeperVictor Didenko
 
RxSwift 시작하기
RxSwift 시작하기RxSwift 시작하기
RxSwift 시작하기Suyeol Jeon
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackVic Metcalfe
 
The Ring programming language version 1.5.1 book - Part 51 of 180
The Ring programming language version 1.5.1 book - Part 51 of 180The Ring programming language version 1.5.1 book - Part 51 of 180
The Ring programming language version 1.5.1 book - Part 51 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88Mahmoud Samir Fayed
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsDavid Golden
 
The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31Mahmoud Samir Fayed
 
An example of R code for Data visualization
An example of R code for Data visualizationAn example of R code for Data visualization
An example of R code for Data visualizationLiang (Leon) Zhou
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsKandarp Tiwari
 
The Ring programming language version 1.10 book - Part 54 of 212
The Ring programming language version 1.10 book - Part 54 of 212The Ring programming language version 1.10 book - Part 54 of 212
The Ring programming language version 1.10 book - Part 54 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196Mahmoud Samir Fayed
 
Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applicationsSkills Matter
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game ProgrammingRichard Jones
 

What's hot (20)

Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
 
The Ring programming language version 1.5.2 book - Part 66 of 181
The Ring programming language version 1.5.2 book - Part 66 of 181The Ring programming language version 1.5.2 book - Part 66 of 181
The Ring programming language version 1.5.2 book - Part 66 of 181
 
Send + More = Money – Let’s mash 2 monads to solve a simple CSP
Send + More = Money – Let’s mash 2 monads to solve a simple CSPSend + More = Money – Let’s mash 2 monads to solve a simple CSP
Send + More = Money – Let’s mash 2 monads to solve a simple CSP
 
The Ring programming language version 1.5.2 book - Part 29 of 181
The Ring programming language version 1.5.2 book - Part 29 of 181The Ring programming language version 1.5.2 book - Part 29 of 181
The Ring programming language version 1.5.2 book - Part 29 of 181
 
PyTrening 2.0 # 15 Okienka GUI
PyTrening 2.0 # 15 Okienka GUIPyTrening 2.0 # 15 Okienka GUI
PyTrening 2.0 # 15 Okienka GUI
 
Ruby is Awesome
Ruby is AwesomeRuby is Awesome
Ruby is Awesome
 
The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210
 
Effector: we need to go deeper
Effector: we need to go deeperEffector: we need to go deeper
Effector: we need to go deeper
 
RxSwift 시작하기
RxSwift 시작하기RxSwift 시작하기
RxSwift 시작하기
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
 
The Ring programming language version 1.5.1 book - Part 51 of 180
The Ring programming language version 1.5.1 book - Part 51 of 180The Ring programming language version 1.5.1 book - Part 51 of 180
The Ring programming language version 1.5.1 book - Part 51 of 180
 
The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88The Ring programming language version 1.3 book - Part 16 of 88
The Ring programming language version 1.3 book - Part 16 of 88
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
 
The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31
 
An example of R code for Data visualization
An example of R code for Data visualizationAn example of R code for Data visualization
An example of R code for Data visualization
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
 
The Ring programming language version 1.10 book - Part 54 of 212
The Ring programming language version 1.10 book - Part 54 of 212The Ring programming language version 1.10 book - Part 54 of 212
The Ring programming language version 1.10 book - Part 54 of 212
 
The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196
 
Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applications
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game Programming
 

Viewers also liked

Baromètre de confiance envers l’exécutif et les principales personnalités pol...
Baromètre de confiance envers l’exécutif et les principales personnalités pol...Baromètre de confiance envers l’exécutif et les principales personnalités pol...
Baromètre de confiance envers l’exécutif et les principales personnalités pol...Harris Interactive France
 
Festividad de la Sagrada familia
Festividad de la Sagrada familiaFestividad de la Sagrada familia
Festividad de la Sagrada familiaICCFMadmin
 
Gdz informatika morze_2009
Gdz informatika morze_2009Gdz informatika morze_2009
Gdz informatika morze_2009Lucky Alex
 
Product Management 101
Product Management 101Product Management 101
Product Management 101Jimmy Skuros
 
Социальная реабилитация пенитенциарной системы Кыргызстана
Социальная реабилитация пенитенциарной системы КыргызстанаСоциальная реабилитация пенитенциарной системы Кыргызстана
Социальная реабилитация пенитенциарной системы КыргызстанаZokirjon
 
Matlab: Programming Environment
Matlab: Programming EnvironmentMatlab: Programming Environment
Matlab: Programming Environmentmatlab Content
 
Chapter 1 -About Matlab
Chapter 1 -About MatlabChapter 1 -About Matlab
Chapter 1 -About MatlabSiva Gopal
 
Simulation of Z-Source Inverter Fed Three Phase Induction Motor Drive
Simulation of Z-Source Inverter Fed Three Phase Induction Motor DriveSimulation of Z-Source Inverter Fed Three Phase Induction Motor Drive
Simulation of Z-Source Inverter Fed Three Phase Induction Motor DriveIJSRD
 
Advantages of direct method
Advantages of direct methodAdvantages of direct method
Advantages of direct methodKharin Anwar
 
Dynamic voltage restorer
Dynamic voltage restorerDynamic voltage restorer
Dynamic voltage restorerLutif Mandhro
 
Audiolingual Method
Audiolingual MethodAudiolingual Method
Audiolingual Methodjesler
 
PRINCIPLE OF CONCRETE MIX DESIGN
PRINCIPLE OF CONCRETE MIX DESIGNPRINCIPLE OF CONCRETE MIX DESIGN
PRINCIPLE OF CONCRETE MIX DESIGNSwarna Rajan
 
Design of Hydraulic Structures
Design of Hydraulic StructuresDesign of Hydraulic Structures
Design of Hydraulic StructuresGAURAV. H .TANDON
 
MATLAB/SIMULINK for engineering applications: day 3
MATLAB/SIMULINK for engineering applications: day 3MATLAB/SIMULINK for engineering applications: day 3
MATLAB/SIMULINK for engineering applications: day 3reddyprasad reddyvari
 

Viewers also liked (17)

Baromètre de confiance envers l’exécutif et les principales personnalités pol...
Baromètre de confiance envers l’exécutif et les principales personnalités pol...Baromètre de confiance envers l’exécutif et les principales personnalités pol...
Baromètre de confiance envers l’exécutif et les principales personnalités pol...
 
Festividad de la Sagrada familia
Festividad de la Sagrada familiaFestividad de la Sagrada familia
Festividad de la Sagrada familia
 
Gdz informatika morze_2009
Gdz informatika morze_2009Gdz informatika morze_2009
Gdz informatika morze_2009
 
Product Management 101
Product Management 101Product Management 101
Product Management 101
 
Matlab: Graph Plots
Matlab: Graph PlotsMatlab: Graph Plots
Matlab: Graph Plots
 
Социальная реабилитация пенитенциарной системы Кыргызстана
Социальная реабилитация пенитенциарной системы КыргызстанаСоциальная реабилитация пенитенциарной системы Кыргызстана
Социальная реабилитация пенитенциарной системы Кыргызстана
 
Matlab: Programming Environment
Matlab: Programming EnvironmentMatlab: Programming Environment
Matlab: Programming Environment
 
Chapter 1 -About Matlab
Chapter 1 -About MatlabChapter 1 -About Matlab
Chapter 1 -About Matlab
 
Educon International School - Presentation
Educon International School - PresentationEducon International School - Presentation
Educon International School - Presentation
 
Simulation of Z-Source Inverter Fed Three Phase Induction Motor Drive
Simulation of Z-Source Inverter Fed Three Phase Induction Motor DriveSimulation of Z-Source Inverter Fed Three Phase Induction Motor Drive
Simulation of Z-Source Inverter Fed Three Phase Induction Motor Drive
 
Advantages of direct method
Advantages of direct methodAdvantages of direct method
Advantages of direct method
 
Dynamic voltage restorer
Dynamic voltage restorerDynamic voltage restorer
Dynamic voltage restorer
 
TESL methodology- Direct Method
TESL methodology- Direct MethodTESL methodology- Direct Method
TESL methodology- Direct Method
 
Audiolingual Method
Audiolingual MethodAudiolingual Method
Audiolingual Method
 
PRINCIPLE OF CONCRETE MIX DESIGN
PRINCIPLE OF CONCRETE MIX DESIGNPRINCIPLE OF CONCRETE MIX DESIGN
PRINCIPLE OF CONCRETE MIX DESIGN
 
Design of Hydraulic Structures
Design of Hydraulic StructuresDesign of Hydraulic Structures
Design of Hydraulic Structures
 
MATLAB/SIMULINK for engineering applications: day 3
MATLAB/SIMULINK for engineering applications: day 3MATLAB/SIMULINK for engineering applications: day 3
MATLAB/SIMULINK for engineering applications: day 3
 

Similar to Selective codes

Matlab ploting
Matlab plotingMatlab ploting
Matlab plotingAmeen San
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1Ke Wei Louis
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring CanvasKevin Hoyt
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualUma mohan
 
Intro to OTP in Elixir
Intro to OTP in ElixirIntro to OTP in Elixir
Intro to OTP in ElixirJesse Anderson
 
Know more processing
Know more processingKnow more processing
Know more processingYukiAizawa1
 
Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.Dr. Volkan OBAN
 
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changeshayato
 
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavSeminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavVyacheslav Arbuzov
 
DSP LAB COMPLETE CODES.docx
DSP LAB COMPLETE CODES.docxDSP LAB COMPLETE CODES.docx
DSP LAB COMPLETE CODES.docxMUMAR57
 
17, r) -,r I -l19.t... 121.2t-314 23. ^t -rr - .docx
17, r) -,r I  -l19.t... 121.2t-314 23. ^t -rr - .docx17, r) -,r I  -l19.t... 121.2t-314 23. ^t -rr - .docx
17, r) -,r I -l19.t... 121.2t-314 23. ^t -rr - .docxhyacinthshackley2629
 
Reactive programming with RxJS - ByteConf 2018
Reactive programming with RxJS - ByteConf 2018Reactive programming with RxJS - ByteConf 2018
Reactive programming with RxJS - ByteConf 2018Tracy Lee
 

Similar to Selective codes (20)

Matlab ploting
Matlab plotingMatlab ploting
Matlab ploting
 
Lập trình Python cơ bản
Lập trình Python cơ bảnLập trình Python cơ bản
Lập trình Python cơ bản
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Intro to OTP in Elixir
Intro to OTP in ElixirIntro to OTP in Elixir
Intro to OTP in Elixir
 
Seminar PSU 10.10.2014 mme
Seminar PSU 10.10.2014 mmeSeminar PSU 10.10.2014 mme
Seminar PSU 10.10.2014 mme
 
Know more processing
Know more processingKnow more processing
Know more processing
 
Python From Scratch (1).pdf
Python From Scratch  (1).pdfPython From Scratch  (1).pdf
Python From Scratch (1).pdf
 
Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.
 
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changes
 
lect.no.3.pptx
lect.no.3.pptxlect.no.3.pptx
lect.no.3.pptx
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
 
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavSeminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
 
Javascript
JavascriptJavascript
Javascript
 
Math 3-H6
Math 3-H6Math 3-H6
Math 3-H6
 
SCIPY-SYMPY.pdf
SCIPY-SYMPY.pdfSCIPY-SYMPY.pdf
SCIPY-SYMPY.pdf
 
DSP LAB COMPLETE CODES.docx
DSP LAB COMPLETE CODES.docxDSP LAB COMPLETE CODES.docx
DSP LAB COMPLETE CODES.docx
 
17, r) -,r I -l19.t... 121.2t-314 23. ^t -rr - .docx
17, r) -,r I  -l19.t... 121.2t-314 23. ^t -rr - .docx17, r) -,r I  -l19.t... 121.2t-314 23. ^t -rr - .docx
17, r) -,r I -l19.t... 121.2t-314 23. ^t -rr - .docx
 
Reactive programming with RxJS - ByteConf 2018
Reactive programming with RxJS - ByteConf 2018Reactive programming with RxJS - ByteConf 2018
Reactive programming with RxJS - ByteConf 2018
 

More from Siva Gopal

FINALL-REPORT-MSD-GROUP-23
FINALL-REPORT-MSD-GROUP-23FINALL-REPORT-MSD-GROUP-23
FINALL-REPORT-MSD-GROUP-23Siva Gopal
 
Chapter 7 - User Controlled Input and Output
Chapter 7 - User Controlled Input and OutputChapter 7 - User Controlled Input and Output
Chapter 7 - User Controlled Input and OutputSiva Gopal
 
Chapter 5 - Plotting
Chapter 5 - PlottingChapter 5 - Plotting
Chapter 5 - PlottingSiva Gopal
 
Chapter 4 - Manipulating Matlab Matrices
Chapter 4 - Manipulating Matlab MatricesChapter 4 - Manipulating Matlab Matrices
Chapter 4 - Manipulating Matlab MatricesSiva Gopal
 
Chapter 3 -Built-in Matlab Functions
Chapter 3 -Built-in Matlab FunctionsChapter 3 -Built-in Matlab Functions
Chapter 3 -Built-in Matlab FunctionsSiva Gopal
 
Chapter 2 - Matlab Environment
Chapter 2 - Matlab EnvironmentChapter 2 - Matlab Environment
Chapter 2 - Matlab EnvironmentSiva Gopal
 

More from Siva Gopal (6)

FINALL-REPORT-MSD-GROUP-23
FINALL-REPORT-MSD-GROUP-23FINALL-REPORT-MSD-GROUP-23
FINALL-REPORT-MSD-GROUP-23
 
Chapter 7 - User Controlled Input and Output
Chapter 7 - User Controlled Input and OutputChapter 7 - User Controlled Input and Output
Chapter 7 - User Controlled Input and Output
 
Chapter 5 - Plotting
Chapter 5 - PlottingChapter 5 - Plotting
Chapter 5 - Plotting
 
Chapter 4 - Manipulating Matlab Matrices
Chapter 4 - Manipulating Matlab MatricesChapter 4 - Manipulating Matlab Matrices
Chapter 4 - Manipulating Matlab Matrices
 
Chapter 3 -Built-in Matlab Functions
Chapter 3 -Built-in Matlab FunctionsChapter 3 -Built-in Matlab Functions
Chapter 3 -Built-in Matlab Functions
 
Chapter 2 - Matlab Environment
Chapter 2 - Matlab EnvironmentChapter 2 - Matlab Environment
Chapter 2 - Matlab Environment
 

Selective codes

  • 1. Selective codes >> x=[0:2:18]; y= [0, 0.33, 4.13, 6.29, 6.85, 11.19, 13.19, 13.96, 16.33, 18.17]; plot(x,y) title('Laboratory Experiment 1') xlabel('Time, sec') ylabel('Distance, ft') grid on ------------------------------------ >> x = 0:pi/100:2*pi; y1 = cos (x*4) ; plot (x,y1) hold on y2 = sin(x) ; plot(x,y2) ----------------------------------- x = 0:pi/100:2*pi; yl = cos(x*4); y2 = sin(x); plot(x,y1,x,y2) y1 = cos(x)*2; y2 = cos(x)*3; y3 = cos(x)*4;
  • 2. y4 = cos(x)*5; plot(x, y1, x, y2, x, y3, x, y4) ---------------------------------- x = [1:10]; y= [58.5, 63.8, 64.2, 67.3, 71.5, 88.3,90.1, 90.6, 89.5, 90.4]; plot(x,y,':ok') ---------------------------------------- x = [1:10]; y= [58.5, 63.8, 64.2, 67.3, 71.5, 88.3,90.1, 90.6, 89.5, 90.4]; plot(x,y,':ok',x,y*2,'--xr',x,y/2,'-b') axis([0,11,0,200]) legend('line 1', 'line 2', 'line3') text(1,100,'Label plots with the text command') ---------------------------------------------------------- x=0:pi/100:2*pi; >> y=sin(x); >> plot(x,y) >> y=abs(sin(x)); >> plot(x,y) ----------------------------------- x=0:pi/20:2*pi; subplot(2,1,1) plot(x,sin(x))
  • 3. subplot(2,1,2) plot(x,sin(2*x)) xlabel('My x label'), ylabel('My y label') title('Example graph for Chapter 5') ---------------------------- x=0:pi/100:pi; y=sin(x); polar(x,y); >> title('Siva') --------------------------- x = 0:0.5:50 ; y = 5*x.^2 ; subplot (2 ,2 , 1) plot (x ,y) title ( ' Polynomial - linear/ linear' ) ylabel ( 'y') , grid subplot (2 ,2 ,2) semilogx (x ,y) title ( ' Polynomial - log/ linear') ylabel ( ' y') , grid subplot (2 ,2 , 3) semilogy (x ,y) title ( ' Polynomial - linear/log' ) xlabel('x') , ylabel('y') , grid subplot (2 ,2 ,4) loglog (x,y)
  • 4. title ( ' Polynomial - log/ log' ) xlabel('x') , ylabel('y') , grid clear, clc x=[1,2,5,4,8]; y=[x;1:5]; subplot(2,2,1) bar(x),title('A bargraph of vector x') subplot(2,2,2) bar(y),title('A bargraph of matrix y') subplot(2,2,3) bar3(y),title('A three dimensional bargraph') subplot(2,2,4) pie(x),title('A pie chart of x') --------------------------------- x = linspace (0,10*pi,1000) ; y = cos (x) ; z = sin(x) ; plot3 (x,y,z) grid xlabel('angle' ) , ylabel(' cos (x) ') zlabel(' sin (x) ') , title('A Spring') ------------------------------------- z = [1,2,3,4,5,6,7,8,9,10; 2,4,6,8,10,12,14,16,18,20
  • 5. 3,4,5,6,7,8,9,10,11,12] ; mesh(z) xlabel('x-axis') ylabel ('y-axis' ) zlabel( 'z-axis' ) ------------------------------- z = [1,2,3,4,5,6,7,8,9,10; 2,4,6,8,10,12,14,16,18,20 3,4,5,6,7,8,9,10,11,12]; x = linspace(1,50,10); y = linspace(500,1000,3); mesh(z) xlabel('x-axis') ylabel('y-axis') zlabe1('z-axis') ------------------------------- x= [-2:0.2:2]; y= [-2:0.2:2]; [X,Y] = meshgrid(x,y); Z = X.*exp(-X.^2 - Y.^2); subplot(2,2,1) mesh(X,Y,Z) title('Mesh Plot'), xlabel('x-axis'), ylabel('y-axis'), zlabel('z-axis') subplot(2,2,2) surf(X,Y,Z) title('Surface Plot'), xlabel('x-axis'), ylabel('y-axis'), zlabel('z-axis')
  • 6. subplot(2,2,3) contour(X,Y,Z) xlabel('x-axis'), ylabel('y-axis'), title('Contour Plot') subplot(2,2,4) surfc(X,Y,Z) xlabel('x-axis'), ylabel('y-axis') title('Combination Surface and Contour Plot') ------------------------------------------ [x,y,z] = peaks; subplot(2,2,1) pcolor(x,y,z) subplot(2,2,2) pcolor(x,y,z) shading interp subplot(2,2,3) pcolor(x,y,z) shading interp hold on contour(x,y,z,20,'k') subplot(2,2,4) contour(x,y,z) function results=f(x) %This function converts seconds %to minutes results = x./60; ------------------------
  • 7. function output=g (x,y) % This function multiplies x and y together % x and y must be the same size matrices a = x.*y; output=a; ------------------------ function [dist, vel, accel] = motion (t) % This function calculates the distance, velocity and acceleration % for a given value of t accel = 0.5 .*t; val = accel .* t; dist = vel.*t; ------------------------------ function[]=star( ) theta = pi/2:0.8*pi:4.8*pi; r=ones(1,6); polar(theta,r) ------------------------------- disp('Hi There'); disp('I"m your Matlab program'); name=input('Who are you? (Enter your name in single quotes) '); disp(['Hi ',name]); answer=input('Don"t you just love computers?') disp([answer,'?']); disp('Computers are very useful');
  • 8. disp('You"ll use them a lot in college!!'); disp('Good luck with your studies') pause(2); disp('Bye bye') ------------------------------ fprintf('Good golly Molly, there are %8.2f cows in the barn',A) -------------------------------- fprintf('5 times %3.0f is %3.0f n' ,my table) ---------------------------------- % An example of a script file % that creates a table of degrees to radians degreestart=input('What starting number of degrees would you like?') degreefinal = input('What final value of degrees would you like?') incr=input('What table increment would you like?'); degree=degreestart:incr:degreefinal; radian=degree*pi/180; table=[degree;radian]; disp('A table of degrees to radians'); fprintf(' %4.2f %6.4f n',table) ---------------------------------- plot(sin(Iinspace(0,4*pi,100))) [xVaIs,yVaIs]=ginput(3) [xVaIs,yVaIs]=ginput(1) -------------------------- xVals=Iinspace(0,pi,300) plot(xVals, exp(-sin(xVals))
  • 9. [xMin,yMin]=ginput(1) --------------------- x = [ 1, 2, 3, 4, 5]; y= [-2, 0, 2, 4, 6]: z = [ 8, 8, 8, 8, 8]; z>x & z>y -------------------------- %Define a vector of mph values mph = 0:10:100; %Convert mph to ft/s fps = mph*5280/3600; %Combine the mph and ft/s vectors into a matrix table = [mph;fps] %Create a table title disp('Velocity Conversion Table') %Create column headings disp('mph f/s') %Display the table fprintf('%8.0f %8.2f n',table) ----------------------- %Define a vector of heights height = [63,67,65,72,69/78,75] %Use the find command to determine which are greater than 66 accept = find(height>=66 ) ----------------------------------- %Define a vector of heights
  • 10. height = [63,67,65,72,69,78,75]; %Use the find command to determine which %are greater than 66 accept = find(height>=66 )A height(accept); %Use the find command to determine which %are less than 66 decline=find(height<66); %Send your results to the command window disp('The following candidates meet the height requirement'); fprintf('Candidate # %4.0f is %4.0f inches tall n', [accept;height(accept)]) -------------------------------------- %Create a 7x2 matrix of applicant height and age information applicants = [63,18:67,19:65,18;72,20;69,36;78,34;75,12] %Use the find command to determine which applicants are eligible pass=find(applicants(:,1)>=66 & applicants(:,2)>=18 & applicants(:,2) < 35) %Use fprintf to create a table of results %First group the results into a table results = [pass,applicants(pass,1),applicants(pass,2)]'; fprintf('Applicant # %4.0f is %4.0f inches tall and %4.0f years oldn',results) ------------------------------------- temp = [95.3, 100.2, 98.6; 97.4,99.2, 98.9; 100.1,99.3, 97]; element=find (temp>98.6) ------------------------------------------------------------ temp = [95.3, 100.2, 98.6; 97.4,99.2, 98.9; 100.1,99.3, 97]; [row,col]=find(temp>98.6);
  • 11. fprintf('Patient%3.0f at station%3.0f had a temp of%6.1f n', [row,col,temp(element)] ’) ---------------------------------------- %Define a vector of x values x=[1,2,3; 10, 5,1; 12,3,2;8, 3,1]; %Find the index munbers of the values in x >9 element = find(x>9); %Use the index numbers to find the x values %greater than 9 by plugging them into x values = x(element) ; % Create an output table disp('Elements greater than 9') disp('Element # Value') fprintf('%8.0f %3.0f n' , [element' ;values']) ----------------------------- count =0 G= [30 , 55 , 10] if G<50 count=count+1 disp (G) end ----------------------------- x=input('To calculate a natural log, enter a value for x: ') if x >0 y = log(x) else disp('The input to the log function must be positive')
  • 12. end ---------------------------- disp('Are you eligible to drive?’) age=input('Enter your age:') if age <16 disp(’Sorry — You"ll have to wait') elseif age<18 disp('You may have a youth license') elseif age<70 disp('You may have a standard license') else disp('Drivers over 70 require a special license') end -------------------------------- city = input('Enter the name of a city in single quotes: ') switch city case 'Boston' disp('$345') case 'Denver' disp('$150') case 'Honolulu' disp('Stay home and study') otherwise disp('Not on file') end --------------------------------
  • 13. city = menu('Select a city from the menu: ','Boston','Denver','Honolulu') switch city case 1 disp(''$345') case 2 disp('$150') case 3 disp('Stay home and study') end ---------------------------- scores = [76,45,98,97]; count = 0; for k=1:length(scores) if scores(k)>90 count: = count + 1; end end disp(count) ------------------------------ scores = [76,45,98,97]; count = 0; k=0; while k<4 k=k+1; if scores(k)>90 count = count + 1;
  • 14. end end disp(count) ---------------------------- n=0; while(n<10) n=n+1; a=input('Enter a value greater than 0:'); if(a<=0) disp('You must enter a positive number ’) disp(' This program will terminate') break end disp('The natural log of that number is') disp(log(a)) end ------------------------------ n=0; while(n<10) n=n+1; a=input('Enter a value greater than 0:'); if(a<=0) disp('You must enter a positive number ') disp(' Try again') continue end
  • 15. disp('The natural log of that number is') disp(log(a)) end ---------------------------- clear, clc A=ones(200); %Creates a 200 x 200 matrix of ones t0=clock; B=A*pi; time = etime(clock, t0) ---------------------------- %Create a 7x2 matrix of applicant height and age information student=[71,62;53,41;62,74;50,91;42,39]; %Find the index munbers of the values in student >50 pass = find(student(:,1)>=50 & student(:,2)>=50); fail = find(student(:,1)<=50 & student(:,2)<=50); reseat= find(student(:,1)<=50 & student(:,2)>=50| student(:,1)>=50 & student(:,2)<=50); %Use fprintf to create a table of results result1 = [pass] fprintf('Student # %4.0f passed n',result1) result2 = [fail] fprintf('Student # %4.0f fail n',result2) result3 = [reseat] fprintf('Student # %4.0f reseat n',result3)