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 Center および File ExchangeNumerical 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