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?

采纳的回答

Image Analyst
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 个评论
Gabriel Oliviero
Gabriel Oliviero 2016-1-24
I fixed that declaring x5 = [].
Thank you for your help!!!
Image Analyst
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 CenterFile Exchange 中查找有关 Annotations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by