Vector must be same lengths - please help me

Dear sir,
I want to plot the graph between w vs x(:,1) from the following codes. but i got error " vector must be same length" like this. I understood that w and x(:,1) are different vectors. I want both w and x(:,1) are should same length.Please help me regarding this.
Function files:
function xdot = f(t,x)
global m k nu N0 N1 F w
xdot = [x(2); (-k/m)*x(1)-((nu*N0)/m)*sign(x(2))-((nu*N1)/m)*sign(x(2))*sin(w*t)+(F/m)*sin(w*t)];
end
Script file:
clc;
clear all;
global m k nu N0 N1 F w
m = 1; k = 1; nu = 0.2; N0 = 1; N1 = 0.1; F = 0.1;
tspan = [0 1];
int = [0 1];
for w = 1:1:10
[t,x] = ode45(@f,tspan,int);
omega(w) = w;
plot(omega, x(:,2));
end
Regards Devarajan K

1 commentaire

John D'Errico
John D'Errico le 1 Juil 2017
Modifié(e) : John D'Errico le 1 Juil 2017
Um, w is NOT a vector. w is a scalar. w is the loop element. Anyway, the plat is between omega, which IS a vector of length 10, and x. What is the size of x? What have you done to ensure that x is the proper size? x is an output from ODE45.

Connectez-vous pour commenter.

Réponses (1)

James Tursa
James Tursa le 1 Juil 2017
I am not exactly sure how you want things plotted, but maybe this?
%plot(omega, x(:,2));
plot(t,x(:,2)); hold on; grid on

2 commentaires

Devarajan K
Devarajan K le 1 Juil 2017
Thanks for your reply. I want to plot omega vs x(:,2).
James Tursa
James Tursa le 1 Juil 2017
Modifié(e) : James Tursa le 1 Juil 2017
Omega is essentially the index of your for loop, a single value. How does it make sense to plot this vs an x(:,2) vector that is 57 elements long? Seems like it makes more sense to plot the time t vs x(:,2) as I have shown, with maybe a legend showing which w goes with which curve?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by