0% found this document useful (0 votes)
57 views13 pages

Assignment Number: 1.1: A, T Be Four Variables

The document describes a MATLAB program to calculate the position of a falling ball at time t=5s. It is given that the initial position (xi) is 10m, initial velocity (vi) is 15m/s, and acceleration (a) is -9.81m/s^2. The program defines the relevant variables, calculates the position using the equation of motion, and displays the result. When run, the program outputs that the position of the ball is -37.625m.

Uploaded by

Jyotibikash Sahu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views13 pages

Assignment Number: 1.1: A, T Be Four Variables

The document describes a MATLAB program to calculate the position of a falling ball at time t=5s. It is given that the initial position (xi) is 10m, initial velocity (vi) is 15m/s, and acceleration (a) is -9.81m/s^2. The program defines the relevant variables, calculates the position using the equation of motion, and displays the result. When run, the program outputs that the position of the ball is -37.625m.

Uploaded by

Jyotibikash Sahu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 13

1

Assignment Number: 1.1

Problem Statement:

The distance traveled by a ball falling in the air is given by the equation
x=xi+vi+1/2*at2 Use MATLAB to calculate the position of the ball at time
t=5s if xi =10m, vi =15m/s,and a=-9.81m/sec2.

Inputs:

Let xi , vi, a, t be four variables.

Outputs:

x= xi + vi*t+ 1/2at2
Pseudocode:

 Read variables x0, vi, a, t -input

 x= xi + vi t+ 1/2at2 -action

 Display x

 Stop

Program: position_of_ball.m

% Script File: position_of_ball


% Purpose: Finding position of ball.
2
% Record of Revision:
% Programmer Date Description of change
%JYOTIBIKASH SAHU 21/08/2016 Original code
% Variable declaration:
% Input Variables:
% xi-initial velocity
% vi-final velocity
% a-acceleration
% t-time
% Output variable
% x=position of the ball
clc;clear all; close all;
xi =10;
vi =15;
a=9.81;
t=5
% Calculation of position:
x= xi + vit+ 1/2*a*t^2;
% Display the result:
disp(‘position of ball’);
disp(x);

Test results:

position of ball
-37.625
3
Assignment: 1.2
Problem statement:

Suppose that x=3 and y=4. Use MATLAB to evalute following expression (x2*y2) / (x-y)2
Input:
Two variables are x,y
Outputs:
r=Solution of the expression contain x,y
Pseudo code:

 Read the variables x,y

 Calculate r=(x2*y3) / (x-y)2

 Display r

Program : evaluate.m

% Script File: evaluate.m


% Purpose:To evaluate the given expression
% Record of Revision:
% Jyotibikash sahu 21/08/2016 Original code
% Variable declaration
% Input Variables
% x=first Variable
% y=second variable
% Output Variable
% r=Result
%%
4
Clc;
Clear all;
Close all;
% Prompt the user to enter inputs
x=input(‘enter the value of x=’);
y=input(‘enter the value of y=’);
% Evalute The Expresion
r=((x^2)*(y^3)) / (x-y)^2
% Display the result
Disp (‘The Result Is’)
Disp (r)
Test Result:

enter the value x=3


enter the value y=4
r=576
5
ASSIGNMENT NUMBER : 1.3a

PROBLEM STATEMENT:-Create sin_x.m in the editor window to calculate


plot the sinusoidal waveform.
and sin_x.m in the command window and then use the
workspace browser to determine that which variables are deifned in the current
workspace.

INPUTS:

Input for sinx:

x ,y

PSEUDO CODE sinx:

 Values are initialized by default.


 calculate values for x.
 plotting the values of x and y.

PROGRAM: sinx

%script file : sinx


%Purpose: To plot a sine wave

%Record of revision:

% Date NAME
%------- ----------------
% 22.08.16 JYOTIBIKASH SAHU

% INPUT VARIABLE:
% x
% OUTPUT VARIABLE:
% Y

%%
clc,clear all,close all;
x=1:0.5:10;

y=sin(x);

plot(x,y);
6
title('sin waveform');
xlabel('x--->');
ylabel('y--->');

TEST RESULT

1). plot of sine waveform

where values of x are:


[ 1 , 1.5 , 2 , 2.5 , 3 ….........., 8.5 , 9 , 9.5 , 10 ]

2). After changing values for variable x

Where x=[ 1 , 1.5 , 3 , 2.5 , 5 ….........., 8.5 , 4 , 9.5 , 10 ]


7

0
8
ASSIGNMENT NUMBER : 1.3b

PROBLEM STATEMENT:-Create two matlab files calc_area.m calculate


the area of rectangle

INPUT:

X = Length of the Rectangle


Y= Width of the Rectangle

OUTPUT

A= area of the rectangle.

PSEUDO CODE Calc_area:

 Read all the values for x and y from x.


 Calculate the area (x*y).
 Display the results

PROGRAM: cal_area

%script file : cal_area

%Purpose: To Calculate the area of a Rectangle

%Record of revision:

% Date NAME
%------- ----------------
%22.08.16 JYOTIBIKASH SAHU

% INPUT VARIABLE:
% X = Length of the Rectangle
% Y= Width of the Rectangle

% OUTPUT VARIABLE:
% a= Area of the Rectangle

%%

clc;clear all; close all;

x=input('ENTER THE LENGTH OF TH RECTANGLE = ');


y=input('ENTER THE BREADTH OF THE RECTANGLE = ');
9
a= x*y;

fprintf('The area of the rectangle is=');

disp(a);

TEST RESULTS

ENTER THE LENGTH OF TH RECTANGLE = 2


ENTER THE BREADTH OF THE RECTANGLE = 5
The area of the rectangle is= 10
ASSIGNMENT NO. 1.6

PROBLEM STATEMENT:- TO generate 3x5 Matrix consisting –


Real numbers, each range from 5 to 20.
Integers , each in the range from 5 to 20.
Generate final matrix after deleting third row from each
matrix.
INPUT:
b1 = FIRST MATRIX CONSISTING OF REAL NUMBERS.
b2= SECOND MATRIX CONSISTING OF INTEGERS.

OUTPUT:
b3= FIRST MATRIX AFTER DELETING 3RD ROW.
b4= SECOND MATRIX AFTER DELETING 3RD ROW.

PSEUDO CODE:
Initialize the 3x5 matrix b1 and b2.
Use operations to delete 3rd row of each matrix.
Display b1,b2,b3,b4

PROGRAM: matrix_opt
%script file : cal_area

%Purpose: To generate 3x5 matrix and perform operatiions

%Record of revision:

% Date NAME
% ------- ----------------
% 22.08.16 JYOTIBIKASH SAHU

% INPUT VARIABLE:
% b1 ,b2
% OUTPUT VARIABLE:
% b3 , b4

%%
Cls;clear all;close all;

b1=[0 1 4 5 3 6; 7 3 6 7 1; 10 0 8 2 1 ];
% Deleting 3rd row for matrix b1
b3=b1[1:2,:]
b2=[6 7 8 9 10; 11 12 7 8 10;11 14 19 18 16];
% Deleting 3rd row for matrix b2
b4=b2[1:2,:]

% Displaying all matrix


fprintf(‘matrix ranging from 0 to 10 is=’);
disp(b1);
fprintf(‘Matrix rsnging from 5 to 20 is = ’);
disp(b2);
fprintf(‘Final matrix after deleting 3rd row ’);
disp(b3);
disp(b4);
ASSIGNMENT NO. 1.4

PROBLEM STATEMENT:-

Test your expression on vectors that have both an odd and even number of elements using
MATLAB

INPUT:
X= reads the matrix from the user

OUTPUT:
E= even position numbers.
O= odd position numbers.

PSEUDO CODE:

 Read the matrix from the user.

 Determining the even and odd numbered elements.

 Displaying the numbers.

PROGRAM: pos_num

%script file : pos_num

%Purpose: To determine the even and odd number position elements

%Record of revision:

% Date NAME
%------- ----------------
%22.08.16 JYOTIBIKASH SAHU

% INPUT VARIABLE:
%X
% OUTPUT VARIABLE:
% e , o
%%

Clc;clear all; close all;

% Prompt user to enter the matrix


X=input(‘Enter the matrix’);

% To split out even postion from the matrix


e=x(1:2:length(x));
% To split out the odd postion from the matrix
o=x(2:2:length(x));

fprintf(‘the even numbered elements are=’);


disp(e);

fprintf(“the odd numbered elements are=”);


disp(o);

Test results:
Enter the matrix

You might also like