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!