主题:刚学这个,真是不会啊。有会的帮个忙 谢谢了
Question 1
Write a MATLAB function that returns the two reals roots of a quadratic equation or prints out an
error message if the roots are complex. Ensure that
1. The functon is called quadratic roots saved in file quadratic roots.m
2. The signiture used is
function [r1,r2] = quadratic roots(a,b,c)
3. Your function should not use any of the built root finding or polynomial functions but instead
find the roots using the formula
x = −b ±
pb2 − 4ac
2a
4. Function should check for invalid input data, i.e., a = 0.
Question 2
Write a MATLAB function that returns the smallest (minimum value) in a list of values (a vector).
1. The functon is called list min saved in file list min.m
2. The signiture used is
function r =list min(c)
3. The min must be found by explicitly iterating over each element in the vector to find the minimun
value (i.e., cannot use buildin min function)
Question 3
Write a MATLAB function that returns the second smallest value in a list of values (a vector).
1. The functon is called list second min saved in file list second min.m
2. The signiture used is
function r =list second min(c)
3. Again cannot used build in functions to preform this task.
Write a MATLAB function that returns the two reals roots of a quadratic equation or prints out an
error message if the roots are complex. Ensure that
1. The functon is called quadratic roots saved in file quadratic roots.m
2. The signiture used is
function [r1,r2] = quadratic roots(a,b,c)
3. Your function should not use any of the built root finding or polynomial functions but instead
find the roots using the formula
x = −b ±
pb2 − 4ac
2a
4. Function should check for invalid input data, i.e., a = 0.
Question 2
Write a MATLAB function that returns the smallest (minimum value) in a list of values (a vector).
1. The functon is called list min saved in file list min.m
2. The signiture used is
function r =list min(c)
3. The min must be found by explicitly iterating over each element in the vector to find the minimun
value (i.e., cannot use buildin min function)
Question 3
Write a MATLAB function that returns the second smallest value in a list of values (a vector).
1. The functon is called list second min saved in file list second min.m
2. The signiture used is
function r =list second min(c)
3. Again cannot used build in functions to preform this task.