I am trying to plot a function with iteration of a variable
1 次查看(过去 30 天)
显示 更早的评论
%%
a = .0022; %m
d = .05*a; %m
viscosity_p = 1.2; %cP
viscosity_c = 3.5; %cP
dpdz1 = -10; %mmHg
dpdz2 = -1.3; %kPa
t = 0;
for r =0:.01:a
Vc(r) = ((r.^2 - (a-d)^2)/(4*viscosity_c))*dpdz1;
Vp(r) = ((r.^3 - ((a-d)^2)*r)/(4*viscosity_p*d))*dpdz1;
t = t+1;
end
plot(Vc,r)
0 个评论
回答(2 个)
Star Strider
2019-11-11
Try this:
a = .0022; %m
d = .05*a; %m
viscosity_p = 1.2; %cP
viscosity_c = 3.5; %cP
dpdz1 = -10; %mmHg
dpdz2 = -1.3; %kPa
t = 0;
rv = linspace(0,a);
for k = 1:numel(rv)
r = rv(k);
Vc(k) = ((r.^2 - (a-d)^2)/(4*viscosity_c))*dpdz1;
Vp(k) = ((r.^3 - ((a-d)^2)*r)/(4*viscosity_p*d))*dpdz1;
t = t+1;
end
plot(Vc,rv)
In MATLAB, indices must be integers greater than 0, so using ‘r’ as an index will not work Also, since ‘a’ is only slightly greater than the 0.01 increment, the colon-described ‘r’ vector contains only one value. The linspace call creates 100 elements in ‘rv’ by default, and as many as you want if you supply a third argument to it.
0 个评论
David Hill
2019-11-11
Not sure what t is, but you do not need a for-loop.
r = 0:.01:a;
Vc = ((r.^2 - (a-d)^2)/(4*viscosity_c))*dpdz1;
plot(Vc,r);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!