Matlab not returning 0 when every element is multiplied by 0.
6 views (last 30 days)
Show older comments
Hi all. I'm currently trying to model couette flow using the following equation
u = @(x1,y1,dP_1) U*(y1/B) + (1/(2*mu))*dP_1*(y1^2-B*y1);
where x and y are a meshgrid of two row vectors
and dp_1 is given by a user specified function of constants, evaluated separately
dP = dP_1(X,Y)
The velocity field is evaluated with
U = u(X,Y,dP);
However, even though every though u depends on y1 and should be zero when y1 = 0, when the function plots at certain inputs y1 is non zero.
I need to know why there are non-zero values. Thanks. The full code is given below.
x=linspace(0,10,10); y=linspace(0,10,10);
%Set X,Y as a meshgrid of x,y [X,Y] = meshgrid(x,y);
%Receive constant inputs from user input boxes a = get(handles.a, 'String'); b = get(handles.b, 'String'); c = get(handles.c, 'String'); d = get(handles.d, 'String'); e = get(handles.e, 'String'); f = get(handles.f, 'String'); g = get(handles.g, 'String'); h = get(handles.h, 'String');
%Convert values from string to num a = str2num(a); b = str2num(b); c = str2num(c); d = str2num(d); e = str2num(e); f = str2num(f); g = str2num(g); h = str2num(h);
if exist(P0) if P0 == 0 a=0;b=0;c=0;d=0;e=0;f=0;g=0;h=0; end end
P = symfun( a*x1^3+b*y1^3+c*x1^2*y1+d*x1*y1^2+e*x1*y1+f*x1+g*y1+h, [x1,y1]); dP_1 = matlabFunction(diff(P,x1))
%Change to user defined height B = get(handles.plate_dist, 'String'); B = str2num(B); U = get(handles.U, 'String'); U = str2num(U); mu = get(handles.mu, 'String') mu = str2num(mu);
dP = dP_1(X,Y)
u = @(x1,y1,dP_1) U*(y1/B) + (1/(2*mu))*dP_1*(y1^2-B*y1);
U = u(X,Y,dP);
V = zeros(numel(x),numel(y));
quiver(handles.axes1,X,Y,U,V)
axis([0 10 0 10])
0 Comments
Answers (1)
Sean de Wolski
on 20 Mar 2015
Are your perhaps forgetting to convert a string '0' to a double?
>> '0'*pi
ans =
150.7964
>> 0*pi
ans =
0
>>
The output from the edit boxes is a string.
0 Comments
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!