fsolve giving error that solution is not finite and real. When I test using vpasolve() I get a solution, then I input the same solution and get same error of not finite/real.

c1 = 0.5176;
c2 = 116;
c3 = .4;
c4 = 0.4;
c5 = 5;
c6 =21;
c7 = .08;
c8 = .035;
syms lambda
for k = 1:600
theta = pitch.Data(k);
%cp(k) = c1*(c2/lambda - c3*theta -c5)*exp(c6/lambda);
cp(k) = c1*(c6*lambda + (-c4 - c3*(2.5 + theta) + c2*(1/(lambda + ...
c7*(2.5 + theta)) - c8/(1 + (2.5 + theta)^3)))/exp(c5*(1/(lambda + ...
c7*(2.5 + theta)) - c8/(1 + (2.5 + theta)^3))));
eqn(k) = cp(k)/(2*lambda^3) == 1e7*(ta_kf.Data(k))/(rho*pi*N^5*wr_kf.Data(k)^2);
tsr(k) = vpasolve(eqn(k),lambda);%
tsr_check(k) = fzero(@(lambda)cp(k),[-1 0]);
end

1 件のコメント

Gordon
Gordon 2022 年 6 月 13 日
Note: I actually gave the input as -1 as an initial guess. The actual solution via vpasolve() is -.6....

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

回答 (1 件)

c1 = 0.5176;
c2 = 116;
c3 = .4;
c4 = 0.4;
c5 = 5;
c6 =21;
c7 = .08;
c8 = .035;
syms lambda
for k = 1:600
theta = pitch.Data(k);
%cp(k) = c1*(c2/lambda - c3*theta -c5)*exp(c6/lambda);
cp(k) = c1*(c6*lambda + (-c4 - c3*(2.5 + theta) + c2*(1/(lambda + ...
c7*(2.5 + theta)) - c8/(1 + (2.5 + theta)^3)))/exp(c5*(1/(lambda + ...
c7*(2.5 + theta)) - c8/(1 + (2.5 + theta)^3))));
eqn(k) = cp(k)/(2*lambda^3) == 1e7*(ta_kf.Data(k))/(rho*pi*N^5*wr_kf.Data(k)^2);
tsr(k) = vpasolve(eqn(k),lambda);%
expr = cp(k)/(2*lambda^3) - 1e7*(ta_kf.Data(k))/(rho*pi*N^5*wr_kf.Data(k)^2);
fun = matlabFunction(expr,'Vars',lambda);
tsr_check(k) = fzero(fun,[-1 0]);
end

8 件のコメント

Gordon
Gordon 2022 年 6 月 13 日
Still have the same error.
Torsten
Torsten 2022 年 6 月 13 日
編集済み: Torsten 2022 年 6 月 13 日
Evaluating your equation for lambda = 0 gives Inf.
Thus use a reasonable starting value or interval for lambda in the call to fzero.
Or use
expr = cp(k) - 1e7*(ta_kf.Data(k))/(rho*pi*N^5*wr_kf.Data(k)^2)*2*lambda^3;
Gordon
Gordon 2022 年 6 月 13 日
As stated before the function should not evaluate to inifinte at the initial guess because I already found an alternate solution using vpasolve() at the same initial guess that is finite and real.
Torsten
Torsten 2022 年 6 月 13 日
As stated before the function should not evaluate to inifinte at the initial guess because I already found an alternate solution using vpasolve() at the same initial guess that is finite and real.
You specify that the solution for lambda lies in the interval [-1 0]. Consequently, fzero evaluates your function at lambda = -1 and lambda = 0, and for lambda = 0 you get a division by zero.
I don't see that you prescribe the solution from vpasolve as initial guess for fzero anywhere.
Gordon
Gordon 2022 年 6 月 13 日
I stated at first that the initial guess wasn't that. Currently I changed the code to evaluate at the correct solution given vpasolve() i.e. tsr(1) as the initial guess. However, now although the solution does not output that the inital guess is not finite or non-zero. The solution evaluates to zero after a few time steps which is incorrect.
Torsten
Torsten 2022 年 6 月 13 日
Then you have to include executable code. In the code supplied, data are missing.
Torsten
Torsten 2022 年 6 月 13 日
@Gordon comment moved here:
fsolve() is not a good enough solver in this situation because of the rate of change of the data. Therefore, vpasolve() needed to be used. The reason for trying to implement fsolve is because simulink does not allow vpasolve() a solution therefore is to use code.extrinsic() to implement function including vpasolve().
Torsten
Torsten 2022 年 6 月 13 日
編集済み: Torsten 2022 年 6 月 13 日
If the solution for index k is "near" to the solution of index k-1, it is usually a good idea to take the solution of step k-1 as initial guess for the solution of index k. Something like
c1 = 0.5176;
c2 = 116;
c3 = .4;
c4 = 0.4;
c5 = 5;
c6 =21;
c7 = .08;
c8 = .035;
tsr_guess = 1.0;
syms lambda
for k = 1:600
theta = pitch.Data(k);
%cp(k) = c1*(c2/lambda - c3*theta -c5)*exp(c6/lambda);
cp(k) = c1*(c6*lambda + (-c4 - c3*(2.5 + theta) + c2*(1/(lambda + ...
c7*(2.5 + theta)) - c8/(1 + (2.5 + theta)^3)))/exp(c5*(1/(lambda + ...
c7*(2.5 + theta)) - c8/(1 + (2.5 + theta)^3))));
eqn(k) = cp(k)/(2*lambda^3) == 1e7*(ta_kf.Data(k))/(rho*pi*N^5*wr_kf.Data(k)^2);
tsr(k) = vpasolve(eqn(k),lambda);%
expr = cp(k)/(2*lambda^3) - 1e7*(ta_kf.Data(k))/(rho*pi*N^5*wr_kf.Data(k)^2);
fun = matlabFunction(expr,'Vars',lambda);
tsr_check(k) = fsolve(fun,tsr_guess);
tsr_guess = tsr_check(k);
end

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

カテゴリ

ヘルプ センター および File Exchange で Multicore Processor Targets についてさらに検索

製品

リリース

R2020b

質問済み:

2022 年 6 月 13 日

編集済み:

2022 年 6 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by