Always getting PFPOWER returns a vector of length 1, but the length of initial conditions vector is 2. pls help
1 次查看(过去 30 天)
显示 更早的评论
I am getting this error when i run my program and enter the values. i have already created cctime.m, pfpower.m and afpower.m files in same directory. But this error always comes:
Error using odearguments (line 93) PFPOWER returns a vector of length 1, but the length of initial conditions vector is 2. The vector returned by PFPOWER and the initial conditions vector must have the same number of elements.
Error in ode45 (line 114) [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in Swingrk4 (line 39) [t1,xf]=ode45('pfpower', tspan, x0); % During fault solution (use with MATLAB 5)
Pls help me. Its my project and i need to develop it urgent.
0 个评论
采纳的回答
Star Strider
2014-11-1
When in doubt, vectorise.
See if this solves the problem:
xdot = [x(2); pi*f./H.*(Pm-E.*V./X2.*sin(x(1)))];
4 个评论
Star Strider
2014-11-2
My pleasure!
This code works perfectly for me, and produced a nice plot:
function xdot = afpower(t,x)
% global Pm E V X1 X2 X3 H f
[Pm,E,V,X1,X2,X3,H,f] = deal(3, 5, 7, 13, 17, 19, 23, 29);
xdot = [x(2); pi*f./H.*(Pm -(E.*V./X3.*sin(x(1))))];
end
tspan = [0 1];
x0c = [1; 0];
[t2,xc]=ode45(@afpower, tspan, x0c); % After fault solution (use with MATLAB 5)
figure(1)
plot(t2,xc)
grid
I suggest you look carefully at whatever ‘tspan’ and ‘x0c’ are. They could be the problem. Also, be sure that your global variables are all within whatever bounds you need them to be.
All I can say is that your ODE functions work in the situations I’ve used them in. I can’t run them with the rest of your code, so if they don’t work in that context, it is necessary for you to see what the time vector and initial conditions, and constants are, and if they could be the problem.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!