I'm facing problem to write a function in which more than 2 variables are varying from one fixed value to another. How to write a function for it?

How to write a function in which more than 2 variables are varying from one fixed value to another. e.g. Y= a*x^2 + b*x + c;
a = 1: 2: 10
b = 1: 1: 20
c = 5: 3: 15
x = 2: 4: 25

 Accepted Answer

How about a bunch of plots where c varies in each plot (lots of curves for different c in each plot), and you get a different plot for each a, b pairing:
a = 1: 2: 10
b = 1: 1: 20
c = 5: 3: 15
x = 2: 4: 25
rows = ceil(sqrt(length(a) * length(b)))
loopCounter = 1;
for k1 = 1 : length(a)
thisa = a(k1);
fprintf('a(%d) = %d\n', k1, thisa);
for k2 = 1 : length(b)
thisb = b(k2);
for k3 = 1 : length(c)
thisc = c(k3);
subplot(rows, rows, loopCounter);
Y = thisa * x .^ 2 + thisb .* x + thisc;
plot(x, Y, '-', 'LineWidth', 2);
hold on;
caption = sprintf('a(%d) = %d. b(%d) = %d\n', k1, thisa, k2, thisb);
title(caption);
end
loopCounter = loopCounter + 1;
drawnow;
end
end

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!