- #1
grandpa2390
- 474
- 14
Homework Statement
I need to write a program in Matlab that accomplishes this graph:
I keep getting an error on Line31 Column 161 about unexpected parenthesis. They look balanced to me. If I take one away from either side, I get an error that I am short a parenthesis.
I also need to change the colors of the lines and position the titles in the proper place by the lines.
Homework Equations
The Attempt at a Solution
Matlab:
close all
clear all
clc
%%defining variables
tmin = 0; %(in seconds)
tmax = 200; %(in seconds)
dt = .1;
vmin = 1; % in m/s
power = 400; % in Watts
mass = 70; % in kg
dragCoefficient = .5
airDensity = 1.225 %kg/m^3
surfaceArea = .33 %in Meters Squared
%%Velocity Without Drag
t = tmin:dt:tmax; % time steps
[j,k] = size(t);
velocityWithoutDrag(1) = vmin;
% calculate instantenous speeds
for i = 2:k
velocityWithoutDrag(i) = velocityWithoutDrag(i-1) + (power.*dt)./(mass.*velocityWithoutDrag(i-1));
end
%%Velocity With Drag
t = tmin:dt:tmax; % time steps
[j,k] = size(t);
velocityWithDrag(1) = vmin;
% calculate instantenous speeds
for i = 2:k
velocityWithDrag(i) = velocityWithDrag(i) + ((power.*dt)./(mass.*velocityWithDrag(i)))-((dragCoefficient.*airDensity.*surfaceArea.*velocityWithDrag(i)^2)/(mass.));
end
%%Plots
figure(1)
hold on
box on
plot(t,velocityWithoutDrag,t,velocityWithDrag)
set(gca,'XScale','lin','YScale','lin')
set(gcf,'Color','w');
set(gcf,'Resize','on');
ylabel('V (m/s)')
xlabel ('time (s)')
text(t(50),velocityWithoutDrag(50),'no air resistance')
title('Bicycling without air resistance')
hold off
I'm sorry. I didn't know about the code tag :(
Attachments
Last edited: