In: Other
What are the restrictions in naming variables and script files in Matlab?
What is the difference between the operators * and .*
What is the function of the commands help, who, and logspace?
Consider the Van der Waals Equation of State for modeling the P-V-T behavior of gases.
.
Suppose a= 3, b=4, V=5; R=8.3, T=400. Write a Matlab code to compute p.
The information regarding MATLAB is as follows:
1) Restrictions in naming variables and script files:
- The variable names for which a particular value or equation is to be assigned should never be named after the functions in matlab such as add, det, plot etc
- The variable name will be valid if it starts with a letter and followed by digits, letters and underscores.
- The variable name should be under the limits provided by the MATLAB which can be known by the command: " namelengthmax"
- MATLAB is case sensitive. The variable name x and X have huge difference.
- The script files name should never be named after the keywords in MATLAB. such as det, plot, subplot.
-The script files name should never be named after the function which you defined in your MATLAB code.
2) Difference between the operators * and .*
the operator * is used to perform multiplication in MATLAB
the operator .* is used to perform element wise product of the vectors.
If a=[1,2;3,4;5,6] and b=[1,2,3;4,5,6]
c = a*b
= 9 12 15
19 26 33
29 40 51
d = a.*b
= 1 4
9 16
25 36
3)Functions of the commands:
help= It obtains help generally or for a specific function
who= It displays the cuurent workspace variable names which have been used till date.
logspace= It is used for creating frequency vectors i.e, it provides space for 50 variables.
4)MATLAB CODE FOR VAN DER WAAL:
function F= vander(V)
a=3;
b=4;
V=5;
R=8.3;
T=400;
f= ((R*T)/(V-b))-(a/V^2);
F=[f;V];