Quadratic question using the function command
古いコメントを表示
Without using the roots command, write a function to calculate roots of the quadratic equation
ax^2+bx+c
Inputs to the function should be the coefficients a, b and c and output should
be the roots. Test your program by setting a=2, b=3 and c= -1
So I know i have to have two files. One with the quadratic equations and the other script recalls the function. Heres What I have so far.
function x=quad_equation(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)
Thats the first file
a=3;
b=3;
c=-1;
function outputs=quad_equation(a,b,c)
output=fzero(
And I am lost on what to do with the second file
採用された回答
その他の回答 (1 件)
abhirup chowdhury
2019 年 12 月 27 日
0 投票
function fx=quad_function(a,b,c)
a=3
b=2
c=-1
a_root=fzero(quad_function,a)
b_root=fzero(fx,b)
c_root=fzero(fx,c)
1 件のコメント
Walter Roberson
2019 年 12 月 27 日
Yes? That duplicates what Chris posted in 2013 ?
カテゴリ
ヘルプ センター および File Exchange で Quadratic Programming and Cone Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!