# Graphs in Matlab

Matlab → Basics → Variables → Graphs Graphs are very useful tool for presenting information as well as very important in analyzing the data. This is particularly true in Business and Science. In this chapter we will learn how to plot two and three dimensional graphs in Matlab. The plot Command Two axes are needed to plot a […]

Posted

# Programming in Matlab

Matlab → Script → Function → Matlab Programming The if-else conditions The if / else conditions are used to make basic decisions in a program. In Matlab, the construction of if-end condition is given as follows. Construction: if-end structure if condition statement; end In the next example, a script is written where the user is asked to insert […]

Posted

# Matlab Script for Black-Scholes Option Price

Matlab → Script → Input, Output → Black-Scholes Price Write a script file where the program ask user to insert stock price, strike, interest rate, volatility, and time. And it should display the European style call and put option values in the style, The value of call is ___, and the value of put is ___. %Call […]

Posted

# Black-Scholes Price for Call and Put Options using Matlab

Matlab → Function → Black-Scholes Option Prices In the next example, call and put option values are calculated using Black-Scholes formula. Remember the option parameter values are given in the command window when we are executing the program. Here we used, , and . % Function calculating call and put function [call, put] = CallPut(s,k,r,v,t) d1=(log(s/k)+(r+v^2/2)*t)/(v*sqrt(t)); d2=d1-v*sqrt(t); […]

Posted

# User-Defined Function in Matlab

Matlab → Built-In Functions → Scripts → User-Defined Functions We studied Matlab built-in functions and Matlab statistical functions in chapter 1. Here we consider user-defined functions where we can build our own functions in Matlab, and then these functions can be used like a built-in function. Functions are normally used for large and complex programs, and in programs where […]

Posted

# Matlab Script File and Function Comparison

Both could be written using “New Script” Both save as .m file In function, the first line is function definition line The variables in a function file are local. The variables in a script file are recognized in the command window. When a function file is saved, the name of the file should be the […]

Posted

# Matlab Input and Output Commands

Matlab → Statistical Functions → Scripts → Input, Output Commands Scripts allow user to input variable values using the input command, and display the result using disp and fprintf commands. The format of these commands are as follows. Input Command Variable-name = input(‘Input message’) First Output Command disp(variable-name) or disp(‘message statement’) Note: The command disp(variable-name) display the value […]

Posted

# Scripts and Functions in Matlab

Matlab → Basics → Statistical Functions → Script File In command window we are unable to save our work to use it in the future. In this chapter we consider scripts and functions which are saved in files and could be used in the future.Normally, we write a set of commands, called a program.Both scripts and functions are […]

Posted

# Generating Random Numbers in Matlab

Matlab → Basics → Arrays → Statistical Functions → Random Numbers Simulations of many physical, financial, and engineering applications frequently require using a number (or a set of numbers) with a random value. Matlab has three commands for this: 1. rand generates uniformly distributed random numbers with values between 0 and 1. That is, in the interval (0,1), […]

Posted

# Statistical Built-In Functions in Matlab

Matlab → Basics → Arrays → Statistical Functions Matlab has several useful built-in statistical functions. For example, consider a vector A, where A=[5 9 2 4] and we are interested in finding mean and variance of this data set. It can easily be done in Matlab using the commands mean and var. For example, >> A=[5 9 2 […]

Posted