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;
0 个评论
回答(1 个)
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);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!