フィルターのクリア

fzero or solve a file full of relations

2 ビュー (過去 30 日間)
David Pesetsky
David Pesetsky 2016 年 6 月 8 日
編集済み: Torsten 2016 年 6 月 9 日
Hi all-
Trying to get it to vary x below until y below is 0.
z=[-300.00 1082.00 7494.20];
x=1.750871192;
zprime=[z(1)*x/10000 z(2)*x/10000 z(3)*x/10000];
a=[1 zprime(3) zprime(2) zprime(1)]';
B=[1.637510856e-06 -2.252209129e-05 0.0001949906158 9.284333582e-06
-2.252209129e-05 0.217829072 0.03330113194 0.0449503853
0.0001949906158 0.03330113194 0.5146272212 0.03759452473
9.284333582e-06 0.0449503853 0.03759452473 0.7076169167];
Ba = B*a;
atBa = a'*Ba;
y=atBa-1;
I think it can be done with fzero which requires no license for solve. But I do have the license for solve if that's the way to go. I hate to fight over limited licenses :)
Hope this one isn't too tough. Need to call it many times, quickly.
Thanks a ton.
Dave

採用された回答

Torsten
Torsten 2016 年 6 月 9 日
Try
function main
x0=1;
sol=fzero(@f,x0);
function y=f(x)
z=[-300.00 1082.00 7494.20];
B=[1.637510856e-06 -2.252209129e-05 0.0001949906158 9.284333582e-06
-2.252209129e-05 0.217829072 0.03330113194 0.0449503853
0.0001949906158 0.03330113194 0.5146272212 0.03759452473
9.284333582e-06 0.0449503853 0.03759452473 0.7076169167];
for k=1:length(x)
xk=x(k);
a=[1 z(3)*xk/10000 z(2)*xk/10000 z(1)*xk/10000]';
y(k)=a'*B*a-1;
end
Best wishes
Torsten.
  2 件のコメント
David Pesetsky
David Pesetsky 2016 年 6 月 9 日
That works. Matches excel's goal seek pretty close.
I don't get the use of the For loop, or how X is getting assigned.
Torsten
Torsten 2016 年 6 月 9 日
編集済み: Torsten 2016 年 6 月 9 日
In function main, you give a starting guess for x (x0=1).
In function f, fzero wants your function to be evaluated at several values of x ( x is a vector here). The for-loop evaluates your function element-wise (in elements xk of the vector x), saves the results in the array y and returns y to fzero.
Best wishes
Torsten.

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2016 年 6 月 8 日
編集済み: Matt J 2016 年 6 月 8 日
You could use either one, but it will be overkill regardless of which one you choose. The problem that you have shown is a 1D quadratic equation in x. You could solve it by hand or with roots().
  2 件のコメント
David Pesetsky
David Pesetsky 2016 年 6 月 9 日
Sorry, I shortened the real problem here to include the linear only terms. It can go up to quadratic, and is transcendental. I guess maybe roots will still solve it? But how to get the coefficients from my matrices to input into roots?
I wouldn't mind some brute force if needed.
Matt J
Matt J 2016 年 6 月 9 日
The coefficients would be obtained by expanding out the terms of atBa. But if the true function is not a polynomial, roots will not solve it.

サインインしてコメントする。

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by