What is the error of my plot?
2 次查看(过去 30 天)
显示 更早的评论
if true
% code
endm5=1.78
c6=0.00036
c7=0.02
c8=0.00004
c9=0.1
k6=167.00
k8=623.00
F = 80
for w= 20:100:1000
x5(end+1) = F/(sqrt(((k6+k8)-(m5*w))^2+((c6+c7+c8+c9)*w)^2))
end
plot (w,x5)
I can't see why the plot is wrong. Could please somebody help?
0 个评论
采纳的回答
Image Analyst
2016-1-24
You're plotting x5 vs the LAST value of w (a scalar that you used as the loop index), not the whole array. Try reassigning w to the whole array before plotting:
w = 20 : 100 : 1000;
plot(w, x5)
3 个评论
Image Analyst
2016-1-24
You might like this code better:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
m5=1.78
c6=0.00036
c7=0.02
c8=0.00004
c9=0.1
k6=167.00
k8=623.00
F = 80
w = 0 : 10 : 1000;
x5 = zeros(size(w));
for index = 1 : length(w)
x5(index) = F/(sqrt(((k6+k8)-(m5*w(index)))^2 + ((c6+c7+c8+c9)*w(index))^2))
end
plot (w,x5, 'b*-', 'LineWidth', 2, 'MarkerSize', 12)
grid on;
xlabel('w', 'FontSize', fontSize);
ylabel('x5', 'FontSize', fontSize);
title('x5 vs. w', 'FontSize', fontSize);
ylim([0, 1.5]);
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by Gabriel', 'NumberTitle', 'Off')
更多回答(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!