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 件のコメント
John D'Errico
2017 年 7 月 1 日
編集済み: John D'Errico
2017 年 7 月 1 日
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.
回答 (1 件)
James Tursa
2017 年 7 月 1 日
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 件のコメント
Devarajan K
2017 年 7 月 1 日
James Tursa
2017 年 7 月 1 日
編集済み: James Tursa
2017 年 7 月 1 日
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?
カテゴリ
ヘルプ センター および File Exchange で Programming についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!