Problem 1: Find all solutions of the equation in the following steps. Define a function
using Matlab's anonymous function syntax. Define a vector x of gridpoints over some appropriate range using Matlab's
linspace
function. Plot versus x and note the approximate values of x where
. Then find precise solutions by calling Matlab's
fsolve
function with the approximate solutions as initial guesses. Plug each precise solution back into to show that
fsolve
in fact produces numerically accurate solutions.
Problem 2: Write an f2c(f)
and a c2f(c)
function that convert Farenheit temperatures to Celsius and vice versa. Each function should print a statement of the form
For input 32 F, the output is 0 C
or
For input 100 C, the output is 212 F
and then return the correct converted temperature. Write the functions in files f2c.m
and c2f.m
. Make sure the functions are correct by checking that the above equivalent temperatures are converted correctly, and by computing f2c(c2f(x))
and c2f(f2c(x))
for a variety of values of x
.
Note: problems 3,4, and 5 use names like mymean
to avoid conflicts with similar built-in Matlab functions.
Problem 3: Write a function mymean(x)
that computes the mean value of the elements in the input vector x
according to the formula
where N is the number of elements. Compute this sum with a for
loop. Figure out a good way to test your function and test it.
Problem 4: Write a function mystd(x)
that computes the standard deviation of the elements in the input vector x
according to the formula
where N is the number of elements in the vector x
and is the mean of
x
. Figure out a good way to test your function and test it.
Problem 5: Write a function mygeomean(x)
that computes the geometric mean of the elements in the input vector x
according to the formula
Figure out a good way to test your function and test it.