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 (최근 30일)
% 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;

답변 (1개)

Jyotsna Talluri
Jyotsna Talluri 2020년 2월 26일
편집: Jyotsna Talluri 2020년 2월 26일
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);

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by