Troubleshooting with fzero command.
1 回表示 (過去 30 日間)
古いコメントを表示
I have a function file and a script file that I am trying to work together in which I am trying to define an implicit equation. I need to find the value of "v" through the equation W = Cd*0.5*ro*v^2*A - N. I treat the equation as if I am trying to find a root through my script file. I loop "T" to get "mu" and "ro". Please view the function file below followed by the script file:
function W = dforce1(v)
global ro d mu A
Re = (ro*v*d)/mu;
Cd = (24/Re)+(6/(1+sqrt(Re)))+0.4;
W = Cd*0.5*ro*v^2*A;
end
________________________________________________________________________________________________________
clear all, close all
global ro d mu A
m = 0.5;
g = 9.8;
N = m*g;
R = 287;
P = 101300;
d = 0.15;
A = (pi*d^2)/4;
b1 = 2.156954157e-14;
b2 = -5.332634033e-11;
b3 = 7.477905983e-8;
b4 = 2.527878788e-7;
T = linspace(213,333,121); NT = length(T); mu = zeros(size(T)); ro = mu;
for i = 1:NT
mu(i) = b1*T(i)^3+b2*T(i)^2+b3*T(i)+b4;
ro(i) = P/(R*T(i));
dF = @(v)dforce1(v)- N;
V = fzero(dF,[1e-10 20]);
end
_________________________________________________________________________________________________________
If the program is ran, the error that shows up is:
Error using fzero (line 274) The function values at the interval endpoints must differ in sign.
Error in dforce_main1 (line 18) V = fzero(dF,[1e-10 20]);
I am puzzled as when I try to change my interval points to different signs, it says that I must use real numbers.
Some things to note:
1). When I remove V = fzero(dF,[1e-10 20]);, my values for ro and mu are real, but when it is left in, they are all zeros.
2). I am also using the global command and I feel that this may be the problem, but when it is removed from both the function and script file, Matlab doesn't know what ro and mu are in the function file.
3). I know that there are real roots to this equation. I have just not been successful in attaining these values for "v"
If anyone knows how to resolve this issue, I would greatly appreciate it. Thank you!
0 件のコメント
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!