Always getting PFPOWER returns a vector of length 1, but the length of initial conditions vector is 2. pls help

조회 수: 3 (최근 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.

채택된 답변

Star Strider
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
Agam Srivastava
Agam Srivastava 2014년 11월 2일
편집: Agam Srivastava 2014년 11월 2일
Thanks very much. It worked for pfpower. but now i am getting same message for afpower even after editing it as same as pfpower. i tried these modifications. Appreciate your help :-)
Help me out! :-(
% code
function xdot = pfpower(t,x)
global Pm E V X1 X2 X3 H f
xdot = [x(2); pi*f./H.*(Pm-E.*V./X2.*sin(x(1)))];
% code
function xdot = afpower(t,x)
global Pm E V X1 X2 X3 H f
xdot = [x(2); pi*f./H.*(Pm -(E.*V./X3.*sin(x(1))))];
Star Strider
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개)

카테고리

Help CenterFile Exchange에서 2-D Function Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by