0% found this document useful (0 votes)
4 views3 pages

Numerical Experiment-3: Objective: Problem Statement

The document outlines a MATLAB numerical experiment focusing on various programming tasks, including creating .m files, performing matrix operations, and generating random numbers. It also covers data import/export, loop structures, logical commands, and basic plotting techniques. Each section includes example commands and code snippets for practical application.

Uploaded by

Devis Kant
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)
4 views3 pages

Numerical Experiment-3: Objective: Problem Statement

The document outlines a MATLAB numerical experiment focusing on various programming tasks, including creating .m files, performing matrix operations, and generating random numbers. It also covers data import/export, loop structures, logical commands, and basic plotting techniques. Each section includes example commands and code snippets for practical application.

Uploaded by

Devis Kant
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/ 3

Numerical Experiment-3

OBJECTIVE: Hands-On MATLAB function

PROBLEM STATEMENT:

1. General purpose commands.


2. Create .m file.
3. Commands for Matrix Multiplications, Division.
4. Comment and uncomment lines in .m file.
5. Generate 100 random numbers by writing .m file and execute.
6. Loading binary files.
7. Importing data into workspace
8. Exporting data from workspace.
9. For and while loop.
10. Logical command.
11. Plotting and Graphics.

SOLUTION:

1.General purpose commands

clc; % Clears command window

clear; % Clears workspace

close all; % Closes all figure windows

who; % Lists variables in workspace

whos; % Detailed info of variables

2. Create .m File :To create a .m file:

 Open MATLAB → Click New Script → Write your code → Save as filename.m

Example content: % myfile.m disp('Hello, MATLAB!')

3. Commands for Matrix Multiplications,

A = [1, 2; 3, 4];
B = [5, 6; 7, 8];

C = A * B; % Matrix multiplication

D = A .* B; % Element-wise multiplication

E = A / B; % Matrix right division (A * inv(B))

F = A ./ B; % Element-wise division

4. Comment and Uncomment Lines in .m File

 Use % to comment:

% This is a comment

 Shortcut:
o Comment: Select lines + Ctrl + R
o Uncomment: Select lines + Ctrl + T

5. Generate 100 Random Numbers and Execute


Create a file random_numbers.m:

numbers = rand(1, 100); % 100 random numbers between 0 and 1

disp(numbers);

6. Loading Binary Files

load('filename.mat'); % Loads MATLAB binary .mat file

7. Importing Data into Workspace

 Use Import Data tool from the Workspace window.

 Or use command: data = readmatrix('data.csv'); % For CSV files

8. Exporting Data from Workspace

save('mydata.mat', 'data'); % Save to .mat file

writematrix(data, 'output.csv');% Export to CSV

9. For and While Loop


% For loop

for i = 1:5

disp(i);

end

% While loop

i = 1;

while i <= 5

disp(i);

i = i + 1;

end

11. Logical Commands

a = 10;
b = 5;

result1 = (a > b); % true

result2 = (a == b); % false


% Logical operations on arrays

A = [1, 2, 3];

B = [3, 2, 1];

C = (A == B); % Logical array

12. Plotting and Graphics


x = 0:0.1:10;
y = sin(x);
plot(x, y);
xlabel('x-axis');
ylabel('sin(x)');
title('Sine Wave');
grid on;

You might also like