1
Review Problems
1. Write a user-defined function with function call C=temp_conv(F) that converts the temperature from
Farenheit Fto Celsius C. Execute the function for the case of F = 86.
Solution
function C = temp_conv(F)
C = (F-32)*100/180;
2. Write a user-defined function with function call [P A]=circ(r) that computes the perimeter Pand area Aof
a circle of radius r. Execute the function to calculate the perimeter and area of a circle with radius r=1.70.
Solution
function [P A] = circ(r)
3. Write a user-defined function with function call val=evalf(f,a,b) where fis an inline function, and a
and bare constants such that
ab
. The function calculates the midpoint
m
of the interval
>@
,ab
and returns
the value of
11 1
23 4
() ( ) ()fa fm fb
. Execute the function for
() cos2
x
fx e x
,
1a
,
3b
.
Solution
4. Write a user-defined function with function call Q = laplace_eval(f,a,b) where fis a function
defined symbolically, and aand bare constants. The function calculates
xx yy
ff
, and evaluates the result at
xa
,
yb
. Execute the function for
2
cos 1/fx y y
,0a ,
1b
.