MATLAB: Fzero or solve a file full of relations

fzerosolve

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

Best Answer

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.