Introduction to vectors, scripts, and functions, MATLAB Programming

In this lab, we study the three concepts. Vector is used to store more than one value into single variable. It is similar to array (other programming language). Script is a collection of statement which is stored into single file name. Function is used to solve the equation and return the result value. It has parameters also.

Sample of Vector:

» x=[-2:5]

x =    -2    -1     0     1     2     3     4     5

Sample of Script:

Impact_v1.m contains,

M=input('Enter the value of m, Mass of the Airplane : ');

V=input('Enter the value of v, Velocity of the Airplane : ');

D=input('Enter the value of Displacement, Displacement of the Airplane : ');


disp('The value of the force is printed below : ');


How to run the Script?

            » run impact_v1

Sample functions:

function f = ImpactForce(m,v,d)

f = 0.5*m*v^2/d ;

We have learned how to work with vectors and plots. As a result of this lab we computed the impact force for initial velocities from 10m/s to 50m/s as shown in Figure 1. The computations are performed in the ImpactForceVec.m function and the script to set up the calculation is called Impact_v3.m.

297_Introduction to Vectors, Scripts, and Functions.png

Figure 1: The figure shows the impact force on the building for initial speeds ranging from 10m/s to 50m/s. The mass of the aircraft is taken to be 10,000kg, and a stopping distance of 15m is used.

Posted Date: 3/9/2013 1:21:58 AM | Location : United States

Related Discussions:- Introduction to vectors, scripts, and functions, Assignment Help, Ask Question on Introduction to vectors, scripts, and functions, Get Answer, Expert's Help, Introduction to vectors, scripts, and functions Discussions

Write discussion on Introduction to vectors, scripts, and functions
Your posts are moderated
Related Questions
Illustration of Output statements: For illustration, >> disp('Hello') Hello >> disp(4^3)   64 The formatted output can be printed to the screen by using the fpr

Function Functions: The one reason for using function handles is to be able to pass functions to the other functions-these are known as function functions. For illustration

Problem 1.  Use Matlab to solve the following system of linear equations: 2x + y + 3z = 1 2x + 6y + 8z = 3 6x + 8y + 18z = 5 Capture Matlab code and the result in a text fi

How do I compute and plot a temperature profile along the x axis from -6 to 6 given the equation for steady state heat conduction and boundary conditions

You are to submit your completed MATLAB code and a short written report through the Blackboard upload facility as a single zip ?le. This zip ?le should consist of your ?nite volume

The Programming Concept: In most of the programming languages, random function returns a real number; therefore the real number would then have to be rounded to produce a rand

The purpose of this assignment is to use Matlab/Simulink to analyse and simulate a mathematical model of an electromechanical system. This system comprises two component subsystems

Expressions: The Expressions can be formed using values, variables which have already been formed, operators, parentheses, and built-in functions. For numbers, these can invol

logical operators: The logical operators are as shown below: All the logical operators operate on Boolean or logical operands. The not operator is a unary operator; wh

You will write functions • B=null basis(A,tol); • B=range basis(A,tol); The function null basis takes a matrix A as input, and outputs a basis for the null space of A, obtained via