operands must be convertible to logical scalar; Help! Urgent!
Show older comments
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
on 27 Feb 2012
http://www.mathworks.com/matlabcentral/answers/29922-why-your-question-is-not-urgent-or-an-emergency
Answers (1)
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
Jan
on 28 Feb 2012
It has been urgent enough to be urgent, but not urgent enough to post a comment to walter's answer or accept it. Then "urgent" means "not so important that I will really care".
Oleg Komarov
on 28 Feb 2012
Personal opinion, I would not allow keywords as urgent, help and matlab among title, tags. And whenever somebody tries to submit a thread with such occurences it should appear a popup saying why it's not urgent (two lines are enough).
Jan
on 28 Feb 2012
But it is possible that a question is urgent. Perhaps I've seen to many action movies.
When "urgent" is blocked, the kewl usrs will write "eargent", "urgnt" or "U_R_G_E_N_T".
On the other hand I frequently delete the "matlab" and "matlab code" tags. They are too redundant here.
Oleg Komarov
on 28 Feb 2012
Well, once hardcoded I bet there are no more than 100 ways to says urgent or emergency or help. Also, as is, this forum is going to be less and less accepted answers which eventually will lead to less and less answers (but I am going off topic here: http://www.mathworks.com/matlabcentral/trendy/plots/748).
Jan
on 28 Feb 2012
Without doubt you are right. Every trial to avoid a "Help! Urgent!" is worth to be implemented, even if it has a limited power.
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
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).
Categories
Find more on Matrix Indexing 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!