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 Exchange에서 Creating 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