Solve with predefined parameters

17 ビュー (過去 30 日間)
Frank
Frank 2011 年 7 月 6 日
Hi. I want to use the solve function using predefined parameters. eg. for equation 0 = a*x^2 +b*x + c
a = 2; b = -1; c = 4
fun = @(x,a,b,c)a*x^2+b*x+c
answer = solve(@(x) fun(x,a,b,c))
Something like this. What is the syntax I should use?

回答 (2 件)

Andrei Bobrov
Andrei Bobrov 2011 年 7 月 6 日
fun = @(a,b,c)roots([a b c])

Titus Edelhofer
Titus Edelhofer 2011 年 7 月 6 日
Hi, usually I would use in the () for the anonymous functions only those variables, which are variable (and not fixed for this run of the code). I.e., I would use
a=2; b=-1; c=4;
fun = @(x) a*x.^2 + b*x+c;
answer = solve(fun);
But your solution should work as well ...
Titus

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by