Lab No. 4 Me
Lab No. 4 Me
Write a function file for the function the input to the function is x
and the output is f(x). Write the function such that x can be a vector. Use the function to
calculate:
a) f(x) for x =6.
b) f(x) for x = 1,3,5,7,9, and 11.
Open the Editor/Debugger Window. This window is opened from the Command Window. In
the File menu, select New, and then select M-fIle. Once the Editor/Debugger Window opens
write the following function in it
y= (x.^4.*sqrt(3*x+5))./(x.^2+1).^2;
Assignment to output
a) Calculating the function for x = 6 can be done by
typing exp4one(6) in the Command window
>> exp4one(6)
ans = 4.5401
To calculate the function for several values of x, a vector with the values of x is first created,
and then used for the argument of the function.
>> x = 1:2:11
x=
1 3 5 7 9 11
>> exp4one(x) ans =
0.7071 3.0307 4.1347 4.8971 5.5197 6.0638
The inline Function
B) 35 degrees F to degrees C
>> FtoC(35)
ans =1.6667
C) 40 degrees F to degrees C
>> FtoC(40)
ans =4.4444
D) 60 degrees F to degrees C
>> FtoC(60)
ans =15.5556
E) 80 degrees F to degrees C
>> FtoC(80)
ans =26.6667
Analysis:
The formula to convert Fahrenheit to Celsius is To convert temperatures in degrees
Fahrenheit to Celsius, subtract 32 and multiply by .5556 (or 5/9).So, in this we apply above formula by
using function F to C which means Fahrenheit to Celsius and write the given value in brackets and the
answer is obtained.
CONCLUSION
In this experiment, we define and uses of function, create a function file in Matlab and to save values in
the function file. Inline functions which are those functions that can be defined in one line and they are
also called one liner as well.
To inline a function, place the keyword inline before the function name and define the function before
any calls are made to the function.