Plotting multiple functions with changing constants
8 次查看(过去 30 天)
显示 更早的评论
I would like to plot the equation for rho as a function of t on two graphs, one with beta=50 and one with beta=60. On each graph, I want to be able to plot each of the 5 curves created by the changing constant v0. Also, I would like for each curve to only be in the range provided. How would I be able to to this?
2 个评论
Image Analyst
2022-5-8
Try this
% Initialization steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 15;
fprintf('Beginning to run %s.m ...\n', mfilename);
g = 9.8;
legendStrings = cell(5, 1);
loopCounter = 1;
for v0 = 30 : 10 : 70
numElements = 1980; % HDTV resolution
p1 = subplot(2, 1, 1);
beta = 50;
% Construct t
t = linspace(0, 2 * v0 * sind(beta)/g, numElements);
% Get rho
rho = ComputeRho(beta, v0, t);
plot(t, rho, '-', 'LineWidth', 2);
grid on;
hold on;
legendStrings{loopCounter} = sprintf('v0 = %d', v0);
title('Beta = 50')
xlabel('t');
ylabel('rho')
drawnow;
p2 = subplot(2, 1, 2);
beta = 60;
% Construct t
t = linspace(0, 2 * v0 * sind(beta)/g, numElements);
% Get rho
rho = ComputeRho(beta, v0, t);
plot(t, rho, '-', 'LineWidth', 2);
grid on;
hold on;
title('Beta = 60')
xlabel('t');
ylabel('rho')
loopCounter = loopCounter + 1;
drawnow;
end
legend(p1, legendStrings, 'Location', 'north');
legend(p2, legendStrings, 'Location', 'north');
function rho = ComputeRho(beta, v0, t)
g = 9.8;
term1 = (v0^2 * cosd(beta).^2) / g;
term2 = -g*t ./ (v0 * cosd(beta));
term3 = sqrt((1 + (term2 + tand(beta)).^2).^3);
rho = term1 .* term3;
end
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Descriptive Statistics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!