Error calling a function or indexing a variable, apparently the first line for plotting is wrong, can't figure out whats wrong with it...

1 view (last 30 days)
% Plotting the error curve
error = ( (40*c) / (m*g) )-( 1-exp( (-10*c)/m ) );
g = 9.81; % gravitational force
m = 68.1; % mass of parachutist
h1 = figure(1);
% Create vectors
c=(0:0.5:25)
y=zeros([1 50])
% Plot the various curves
plot(c, error(c, m, g)), 'r--', 'Linewidth', 3);
hold on;
plot(c,y,'k-', 'Linewidth', 3);
plot(5, error(5, m, g)),'.b', 'markersize', 10);
plot(c,y,'k-', 'Linewidth', 3);
xlabel('Drag coefficient c', 'fontsize', 20);
ylabel('Error', 'fontsize', 20);
title('Error as a function of c', 'fontsize', 20);
grid on;

Answers (1)

Jyotsna Talluri
Jyotsna Talluri on 26 Feb 2020
Edited: Jyotsna Talluri on 26 Feb 2020
error(c,m,g) is a call to the function error with input variables c,m,g .But you have not declared the error as a function ,you declared it as an expression depending on variables c,m,g .Also,the variables have to be declared before the expression.
g = 9.81; % gravitational force
m = 68.1; % mass of parachutist
error=[];
for c = 0:0.5:25
error(end+1)= ( (40*c) / (m*g) )-( 1-exp( (-10*c)/m ) );
end
y=zeros([1 50]);
h1 = figure(1);
plot(c, error, 'r--', 'Linewidth', 3);
hold on;
plot(c,y,'k-', 'Linewidth', 3);

Categories

Find more on Author Block Masks in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!