Effacer les filtres
Effacer les filtres

What is the error of my plot?

2 vues (au cours des 30 derniers jours)
Gabriel Oliviero
Gabriel Oliviero le 24 Jan 2016
Commenté : Image Analyst le 24 Jan 2016
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?

Réponse acceptée

Image Analyst
Image Analyst le 24 Jan 2016
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 commentaires
Gabriel Oliviero
Gabriel Oliviero le 24 Jan 2016
I fixed that declaring x5 = [].
Thank you for your help!!!
Image Analyst
Image Analyst le 24 Jan 2016
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')

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by