NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

I. Type the following in the command window and write down the results
(1) x=3
(2) x=7*8;
y=x*1.28
(3) clear all
(4) initial_velocity = 0;
acceleration = 9.8;
time = 20;

ECL 201 Scientific Computing Laboratory 2020

Dept. Of Electronics and Communication Engineering
final_velocity = initial_velocity + acceleration * time
(5) x = sqrt(16)
(6) clc
(7) help sqrt
(8) disp a
(9) a=2;
disp(a)
(c) Familiarization of data types in the language used
MATLAB does not require any type declaration or dimension statements. Whenever MATLAB
encounters a new variable name, it creates the variable and allocates appropriate memory space.
Data Types Available in MATLAB
MATLAB provides 15 fundamental data types. Every data type stores data that is in the form of a
matrix or array. The size of this matrix or array is a minimum of 0-by-0 and this can grow up to a
matrix or array of any size.
Sr.No. Data Type & Description

1
int8
8-bit signed integer
2
uint8
8-bit unsigned integer
3
int16
16-bit signed integer
4
uint16
16-bit unsigned integer

ECL 201 Scientific Computing Laboratory 2020

Dept. Of Electronics and Communication Engineering
5
int32
32-bit signed integer

6
uint32
32-bit unsigned integer
7
int64
64-bit signed integer
8
uint64
64-bit unsigned integer
9
single
single precision numerical data
10
double
double precision numerical data
11
logical
logical values of 1 or 0, represent true and false respectively
12
char
character data (strings are stored as vector of characters)
13
cell array
array of indexed cells, each capable of storing an array of a different dimension and data type
14
structure
C-like structures, each structure having named fields capable of storing an array of a different
dimension and data type
15
function handle
pointer to a function
16
user classes

ECL 201 Scientific Computing Laboratory 2020

Dept. Of Electronics and Communication Engineering
objects constructed from a user-defined class
17
java classes
objects constructed from a Java class

(d) Familiarization of the syntax of while, for, if statements.
II (1) Execute a script (m file) to check whether a number is divisible by 3
PROCEDURE

1. Open MATLAB ®
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. For the output see command window Figure window

PROGRAM
clc;
clear all;
close all;
a=input('enter value of a');
if mod(a,3)==0
disp ('divisible by 3')
else
disp ('not divisible by 3')
end

INPUT
enter value of a 12
OUTPUT
divisible by 3
(2) Execute a script (m file) to check whether a number is prime or not using while loop
PROGRAM

ECL 201 Scientific Computing Laboratory 2020

Dept. Of Electronics and Communication Engineering
clc;
clear all;
close all;
n=input('enter number');
i=2;
while i<=n/2
if mod(n,i)==0
flag=1;
break;
end
i=i+1;
end
if n==1
disp('neither prime nor composite');
else
if flag==1
disp('not prime');
else
disp('prime');
end
end

(3) Execute a script (m file) to check whether a number is prime or not using for loop
PROGRAM
clc;
clear all;
close all;
n=input('enter number');
for i=2:n/2
if mod(n,i)==0
flag=1;
break;
end
end
if n==1
disp('neither prime nor composite')
else
if flag==1
disp('not prime')
else
disp('prime')
end
end
INPUT
enter number 12
OUTPUT

ECL 201 Scientific Computing Laboratory 2020

Dept. Of Electronics and Communication Engineering
not prime
(e) Basic syntax and execution of small scripts.
III 1. Execute a script (m file) to create an array whose starting value is 100 and ends at 50 with a
decrement of 7
PROGRAM
clc;
clear all;
close all;
a=[100:-7:50];
disp(a)
OUTPUT
[100 93 86 79 72 65 58 51 ]
2. Execute a script (m file) to add two matrices
PROGRAM
clc;
clear all;
close all;
a=[1 3;4 5;7 9];
b=[3 4;4 3;5 6];
c=a+b;
disp (c)
OUTPUT

4 7
8 8
12 15
3. Execute a script (m file) to find transpose of a matrix
PROGRAM
clc;
clear all;
close all;
a=[1 3;4 5;7 9];
c=a';

ECL 201 Scientific Computing Laboratory 2020

Dept. Of Electronics and Communication Engineering
disp (c)

OUTPUT
1 4 7
3 5 9
4. Execute a script (m file) to display the second row of a 3x3 matrix as the output
PROGRAM
clc;
clear all;
close all;
a=[1 3 3;4 5 6;7 8 9];
a(2,:)

OUTPUT
[4 5 6]
5. Execute a script (m file) to display the second row third column element of a 3x3 matrix as the
output
PROGRAM
clc;
clear all;
close all;
a=[1 3 3;4 5 6;7 8 9];
a(2,3)
OUTPUT
ans =6
6. Execute a script (m file) to do element by element multiplication of 2 matrices
clc;
clear all;
close all;
a=[1 3 3;4 5 6;7 8 9];
b=[1 5 2;2 2 3; 1 2 3];
a.*b

ECL 201 Scientific Computing Laboratory 2020

Dept. Of Electronics and Communication Engineering
OUTPUT
1 15 6
8 10 18
7 16 27
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.