Using fzero solving function between two bounds

9 visualizzazioni (ultimi 30 giorni)
Hi all.
I have tried to search up this issue I am having with the search function and have tried to find similar implementations but so far turned up nothing! This is my first time asking a question on here so please feel free to ask anything I haven't offered to help solve the issue.
I am trying to solve for an angle phistar between two bounds, sim,epsilon (1e-6) and pi/2 if f_func @ pi/2 > 0.
f_func is a function containing more than just the angle variable.
f_func returns decimals, both positive and negative of magnitude less than 2 when I run the main script.
When I run my main code, I get this error. This doesn't make sense to me as my interval endpoints are finite and real?!?
I have tried implementing fsolve, lsqnonlin and fminsearch but to no avail.
Can anyone suggest an alternative solving function or see any errors in the function syntax?
function [phistar] = BEMSOLVE(phiv,rotor,sim)
%%% Function to solve Blade Element Momentum Theory Equations via Ning's Implementation
if f_func(pi/2,rotor,sim) > 0
phistar = fzero(@(phiv) f_func(phiv,rotor,sim),[sim.epsilon,pi/2]);
elseif (fPB_func(-pi/4,rotor,sim) < 0 && fPB_func(sim.epsilon,rotor,sim) > 0)
phistar = fzero(@(phiv) fPB_func(phiv,rotor,sim),[-pi/4,-sim.epsilon]);
else
phistar = fzero(@(phiv) f_func(phiv,rotor,sim),[pi/2,pi]);
end
  6 Commenti
John D'Errico
John D'Errico il 2 Feb 2021
fzero CANNOT solve an array. You could use arrayfun, if you know what you are doing, but it is simpler to just use a loop.
Johnny Dewhurst
Johnny Dewhurst il 4 Feb 2021
The solution I came up with was to use a temporary input for each iteration, ensuring I was passing a single element, rather than an array to fzero as below. I hope this comes in handy for others!
phistar = cell(1,sim.N); % Allocating phistar
for i = 1:sim.N % Looping elements radially
rotor.spani = linspace(turbine.hub,turbine.tip-0.1,sim.N);
rotor.solidityi(i) = interp1(input.span,input.solidity,rotor.spani(i),'linear','extrap');
rotor.twisti(i) = interp1(input.span,input.twist,rotor.spani(i),'linear','extrap');
rotor.Ci(i) = rotor.solidityi(i)*2*pi.*rotor.spani(i)/turbine.B;
rotor.alphav(i) = phi(i)-rotor.twisti(i);
temp_rotor.spani = rotor.spani(i); % Interpolated span [m]
temp_rotor.solidityi = rotor.solidityi(i); % Interpolated solidity [-]
temp_rotor.twisti = rotor.twisti(i); % Interpolated twist [radians]
temp_rotor.Ci = rotor.Ci(i); % Interpolated Chord [m]
temp_rotor.alphav = rotor.alphav(i); % Local AoA [radians]
phistar{i} = BEMSOLVE(phi(i),rotor,temp_rotor,sim);
clear i
end

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by