for loops, how to see the effect of a parameter

3 Ansichten (letzte 30 Tage)
Lily
Lily am 16 Mär. 2018
Bearbeitet: Lily am 16 Mär. 2018
Simplified version of moy code is somethig like this:
theta=2;
beta=8;
W=30;
bound=W./(theta+beta)
step=bound/1000;
R=[0:step:bound];
V=R.^2+3*theta+beta*W;
figure; plot(R,V); xlabel('R'); ylabel('V');
I would like to see the effect of theta. So for example theta= [2 4 6 ] Since bound, hence R range, depend on theta, the for loops or functions I write are not working. Any help on how to write the code is appreciated

Antworten (1)

KALYAN ACHARJYA
KALYAN ACHARJYA am 16 Mär. 2018
theta=2;
beta=8;
W=30;
bound=W./(theta+beta)
step=bound/1000;
R=[0:step:bound];
for theta=theta:10 % you can change this range
V=R.^2+3*theta+beta*W;
plot(R,V);
hold on;
theta=theta+2;
end
xlabel('R'); ylabel('V');
hold off;
  1 Kommentar
Lily
Lily am 16 Mär. 2018
Bearbeitet: Lily am 16 Mär. 2018
I guess my previous answer is deleted. Thank you for your time. The problem is with this code the range for R is fixed. However in my problem, the range for R is changing as a function of theta, since "bound" is function of theta. Thanks

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by