Matla Assignment 3
Matla Assignment 3
1)
The command that we used to complete the task that been given during the class sesssion is
as shows below:
function x = rqe(a,b,c)
x(1) = (-b + sqrt(b^2 - 4 * a * c))/(2*a);
x(2) = (-b - sqrt(b^2 - 4 * a * c))/(2*a);
We enter the coefficients as parameters when we call the function. We assign to variables x(1)
and x(2) the calculated values using the formula, and the returning result x is a vector
containing x(1) and x(2).
We could use the following Matlab code instead, to return two separate variables:
function [x,y] = rqe2(a,b,c)
x = (-b + sqrt(b^2 - 4 * a * c))/(2*a);
y = (-b - sqrt(b^2 - 4 * a * c))/(2*a);
0.5000
-1.0000
We can call our second function (second code above) like this:
[m, n] = rqe2(2, 1, -1)
0.5000
n =
-1
2)