How do I change only one variable in an equation and plot the response for this equation on a graph for all of the different values of this one variable?

2 views (last 30 days)
Robbie Kemlo on 29 Mar 2023
Moved: Torsten on 29 Mar 2023
Trying to plot a resonance curve, but using multiple vlues for the damping ratio variable. I know and can successfully plot the resonance curves individually but how do i write the script so that it knows to change the damping ratio value and plot each response for each of the different damping ratios on one graph?
I tried setting it up as an array i.e. DR = [0, 0.2, 0.4, 0.6, 0.8];
but it just came up with the error "Arrays have incompatible sizes for this operation".
Here is part of my code for just one damping ratio value.
DR = 0; % Damping ratio
A = (F/K) ./ sqrt(((1 - (r.^2)).^2) + (4.*DR.^2.*r.^2));
0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

Answers (2)

Catalytic on 29 Mar 2023
Edited: Catalytic on 29 Mar 2023
F=1;K=1;
DR = [0, 0.2, 0.4, 0.6, 0.8];
r=linspace(0,5)';
A = (F/K) ./ sqrt(((1 - (r.^2)).^2) + (4.*DR.^2.*r.^2));
plot(r,A); xlabel r;ylabel A; legend("DR="+DR)
0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

Torsten on 29 Mar 2023
Moved: Torsten on 29 Mar 2023
So you want to plot A against r for different values of DR ?
F = 1.0;
K = 1.0;
r = 0:0.01:1;
DR = [0.1, 0.2, 0.4, 0.6, 0.8].';
A = (F/K) ./ sqrt(((1 - (r.^2)).^2) + (4.*DR.^2.*r.^2));
plot(r,A)
grid on
0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

Categories

Find more on Line Plots 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!