For loops for multiple variables

Hello there!
I want to generate 3 graphs of y vs x with three different boundaries (C). However, I need to assume that changing C also changes 2 other parameters (m and rho), I mean for each of C there are certain values for those two parameters. In reality, I have to take 3 graphs, but I obtain around 27 graphs. What I made so far is the following:
C = [0.342 0.599 0.856];
m =[0.000755 0.000870 0.000969]; % viscosity [Pa s]
rho = [1022 1028 1035]; % density of seawater [kg m-3]
D = 1.5e-9; % diffusion coefficient [m2 s-1]
k = 1.42e-5; % membrane permeability [m2 s-1]
for i = 1:length(C)
for j = 1:length(m)
for l = 1:length(rho)
b = - m(j) / (rho(l)*k*D);
fun1 = @(x,Y)[Y(2);-(Y(2).*(x.^2.*b+1.0))./x];
R1 = 1.63e-4; % inner radius [m]
R2 = 2.5e-4; % outer radius [m]
bc = @(ya, yb) [ya(1) - (C(i)-0.9998*C(i)); yb(1)- C(i)];
xmesh = linspace(R1, R2, 5000);
solinit = bvpinit(xmesh, [1 0]);
sol = bvp4c(fun1, bc, solinit);
figure(1);
plot(sol.x, sol.y(1,:),'LineWidth',2); hold on;
set(gca, 'XDir','reverse')
end
end
end
Thanks in advance. Any comment is highly appreciated.

 Accepted Answer

Rik
Rik on 5 Dec 2020
Edited: Rik on 5 Dec 2020
You only need a single loop:
for n = 1:length(C)
m_=m(n);
rho_=rho(n);

More Answers (0)

Categories

Find more on Loops and Conditional Statements 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!