operands must be convertible to logical scalar; Help! Urgent!

1 view (last 30 days)
This is my script file, I want to give z range, say from 0.001 to 0.1 with an increment of 0.01, and solve the value for r and plot r.
for i = 1:1:100; % loop counters must be nonzero, positive integers
r = i/1000; % this will give us 0.001 resolution
press(i) = r;
%Dt is the metabolite tissue diffusivity
Dt=8*10^(-6);
%V is the blood plasma velocity
V=0.005;
%rc is the capillary radius
rc=0.0005;
%tm is the capillary wall thickness
tm=5*10^(-5);
%K0 is the overall metabilite mass transfer rate
K0=5.75*10^(-5);
C0=5;
R0=0.01;
y=r/(rc+tm);
z(i)=((y^2*log(y^2)-y^2+1-(4*Dt*C0/(R0*(rc+tm)^2))...
+(2*Dt/(rc*K0))*(y^2-1))/((4*Dt/(V*rc^2))*(1-y^2)));
end
hold on
plot(press,z); axis equal; grid
xlabel('rcrit');
ylabel('z')
%
% Get user input for z
% OK, we need to pass this info to the function, and the easiest way is to
% do so as a global variable
global Z
SAT = 0.01;
%
% Choose initial guess
rcrit = 0.005;
[rcrit, errorStructure, exitflag, output] = fzero(@Krogh, rcrit);
%
% OK, what's the solution, how many iterations, what's the error?
fprintf(' pO2 (Iterations Z Error) \n')
fprintf(' %6.3f %2u %6.2f %+6.2E \n',...
r, output.funcCount, Z, errorSturcture)
plot(r,0.01,'o')
First, I don't know how to give z a series of numbers, I tried z=[0.001:0.01:0.1] but failed.
Second, matlab said:
Operands to the || and && operators must be convertible to logical scalar values.
Error in fzero (line 308)
elseif ~isfinite(fx) || ~isreal(fx)
Error in YZHW63 (line 44)
[rcrit, errorStructure, exitflag, output] = fzero(@Krogh, rcrit);
When I run my file.
Can anyone tell me how to do this? Reall appriciate!
  1 Comment
Walter Roberson
Walter Roberson on 27 Feb 2012
http://www.mathworks.com/matlabcentral/answers/29922-why-your-question-is-not-urgent-or-an-emergency

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 15 Feb 2012
You declare Z as a global variable but you do not assign any value to it.
You calculate the array z in a loop, so it is not clear why you would want to assign an array of values to z.
MATLAB is case sensitive, and it is an error to declare a variable global after the variable has been given a value.
You do not show us the source for Krogh.
The easiest way to pass additional information to a function for fzero is to use an anonymous function:
fzero(@(x) Krogh(x,Z), rcrit)
  7 Comments
Walter Roberson
Walter Roberson on 28 Feb 2012
"There must be 50 ways to write Viagra": http://www.jgc.org/pdf/jgc-march-2004-virus-bulletin.pdf
However, 50 is a vast underestimate. One of the well-known spam fighters did a calculation based upon extra letters, letter substitutions, use of numbers, spacing, and so on; the figure they came up with for ways recognizable to humans was in the trillions (something on the order of 10^26 or so.)
Oleg Komarov
Oleg Komarov on 28 Feb 2012
However, the objective is to pop-up an alert which explains why such keywords are not allowed. So the objective is accomplished, i.e. to show your post automatically withouth having to post the link every time.
If the poster persists and come up with H.@lp, more reason for me NOT to answer him (that is to waste my time).

Sign in to comment.

Categories

Find more on Function Creation in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!