MATLAB Answers

0

It shows: Undefined function 'vpasolve' for input arguments of type 'double' when I run it. Can I know how to solve this?

Asked by Sylvia Tan on 15 Feb 2019
Latest activity Edited by John D'Errico
on 15 Feb 2019
clear all
clc
Q=((2000*42*(3.785*10^-3))/(1*24*3600)); %volumetric flowrate of fluid in m3/s
D=(4*0.0254); %inner diameter of pipe in m
A=(pi()*(D^2))/4; %cross sectional area of pipe in m2
rho=(0.9*1000); %density of fluid in kg/m3
miu=(8*0.001); %viscosity of fluid in Pa.s
Re=(rho*D*Q)/(miu*A); %Reynolds number
for rr=[0:0.002:0.008]; %relative roughness
%f is fricton factor
syms f
f=zeros(rr);
fn=1+2.*sqrt(f).*log(((rr)./3.7)+(2.51./(Re.*sqrt(f))));
f=double(vpasolve(fn==0,f,[0 1]))
end

  0 Comments

Sign in to comment.

1 Answer

Answer by John D'Errico
on 15 Feb 2019
Edited by John D'Errico
on 15 Feb 2019

Is f a symbolic variable? (No.) We see this:
syms f
f=zeros(rr);
fn=1+2.*sqrt(f).*log(((rr)./3.7)+(2.51./(Re.*sqrt(f))));
f=double(vpasolve(fn==0,f,[0 1]))
So you created f as symbolic. And people seem to think that having done so, it will stay that way.
But in the very next line, you replace f.
f=zeros(rr);
f is now a double variable. Zero, in fact, although the first time through the loop, it will be empty, since rr will be 0.

  0 Comments

Sign in to comment.