Multiply Matrix by scalar variables?
239 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ron Wicker
le 11 Nov 2017
Commenté : Star Strider
le 11 Nov 2017
I am trying to output a plot of C vs v_f, where v_f is a matrix containing all of the x values for my data points. C is dependent on v_f through a system of equations.
I've run into trouble with the matrix multiplication and keep. I just want all the other variables to act as scalars on every x value in v_f, and output every corresponding y value, but I'm getting a matrix multiplication error.
Error using /
Matrix dimensions must agree.
Error in FILTRATION2 (line 24)
n_G = ((rho_p - rho_w)*g*(d_p).^2)/(18 * mu * v_f);
This is my script:
%Ask for input for particle diameter
d_f = input('Enter particle diameter in um');
d_p =(d_f)*10^-6; %convert to m
%Define Vector for Filtration Velocity
v_ff = [1:.1:25] ; %m/h
v_f = (v_ff)/3600; %m/s
%Define Known Variables
L = 1; %m
E = 0.42;
a = 1;
Ha = 10^-20; %J
d_c=(0.0005); %m
rho_p = 1020; %kg/m^2
rho_w = 998.2; %kg/m^2
g = 9.81; %m/s^2
mu = .001002; %Ns/m^2
k_B = 1.381*10^-23; %J/K
T = 293; %K
%Define Dependent Variables
n_I = (3/2)*(d_p / d_c).^2;
n_G = ((rho_p - rho_w)*g*(d_p).^2)/(18 * mu * v_f);
n_D = 0.9*((k_B*T)/(mu * d_p * d_c * v_f)).^(2/3);
X = n_I + n_G + n_D;
%Define C/Co
C = exp(((-3/2)*(1-E)*X*a*L)/d_c);
%Plot C/Co
plot(v_f,C);
xlabel('Filtration Velocity (m/h)');
ylabel('C/Co');
title('Filter Performance with __ um')
Any help is appreciated on how I can go about solving this problem. Normally I would use excel but this Thank you!
0 commentaires
Réponse acceptée
Star Strider
le 11 Nov 2017
You need to vectorise the division (replace ‘/’ with ‘./’). Then it works:
... CODE ..
%Define Dependent Variables
n_I = (3/2)*(d_p / d_c).^2;
n_G = ((rho_p - rho_w)*g*(d_p).^2)./(18 * mu * v_f);
n_D = 0.9*((k_B*T)./(mu * d_p * d_c * v_f)).^(2/3);
X = n_I + n_G + n_D;
%Define C/Co
C = exp(((-3/2)*(1-E)*X*a*L)/d_c);
%Plot C/Co
plot(v_f,C);
xlabel('Filtration Velocity (m/h)');
ylabel('C/Co');
title(sprintf('Filter Performance with %.1f \\mum', d_f))
I didn’t copy all your code to my Answer, only the part that needed help. I also got the impression you wanted ‘d_f’ to be displayed in the title, so I added that.
2 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!