How to run Fsolve using vectors

Hi everyone. I am trying to run fsolve using vectors as inputs but it doesn't seem to work. My code is below. Do I have a syntax error?? I get x=[1 1 1 0.005348] as output. Seems that first 3 elements are just the same as initial condition. Any ideas?:
a = [2 1 3 4];
b = [-5 -10 -20 -30];
for i = 1:length(a)
F = @(x) ((log(x(i)^a(i)) - x(i)) - b(i));
x0=[1 1 1 1];
x = fsolve(F,x0,optimset('Display','none'));
end

回答 (1 件)

Torsten
Torsten 2015 年 10 月 13 日

1 投票

a = [2 1 3 4];
b = [-5 -10 -20 -30];
F = @(x)log(x.^a)-x-b;
x0 = [1 1 1 1];
x = fsolve(F,x0,optimset('Display','none'));
Best wishes
Torsten.

2 件のコメント

Fotis
Fotis 2015 年 10 月 13 日
Thanks Torsten!
BB
BB 2021 年 12 月 4 日
Great script, helped me a lot!

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

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

質問済み:

2015 年 10 月 13 日

コメント済み:

BB
2021 年 12 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by