How can I calculate x for each associated Ho?

1 view (last 30 days)
Hi, I tried to calculate x value for each Ho in the following equation by using fzero function. but there is an error which avoids running the code properly, I am interested in having 7 values for x, eventually 7 tetas in the equations:
Equations:
Jo=[0.74]; Jw=[0.35 0.25 0.19 0.12 0.08 0.06 0.04]; Jmix=Jo+Jw; ew=Jw./Jmix; Hw=((1+0.35.*(1-ew))).*ew; Ho=1-Hw;
fun=@(x) 2*pi.*Ho-2*pi+x-sin(x); teta=fzero(fun,[0 2*pi])
error:
Operands to the and && operators must be convertible to logical scalar values.
Error in fzero (line 423) while fb ~= 0 && a ~= b
Error in a (line 4) teta=fzero(fun,[0 2*pi])
is there anybody to help me how I can remove this error?

Accepted Answer

Star Strider
Star Strider on 30 Mar 2015
Use a for loop and iterate through the values for ‘Ho’:
fun=@(x,Ho) 2*pi*(Ho-1)+x-sin(x);
for k1 = 1:length(Ho)
teta(k1)=fzero(@(x) fun(x,Ho(k1)),[0 2*pi]);
end
teta % Display Results
produces:
teta =
2.8164 2.5552 2.3515 2.0350 1.7840 1.6225 1.4175

More Answers (0)

Categories

Find more on Optimization in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!