I have prepared MATLAB code using ODE45 for calling function. Its giving error as "input argument 'z' is undefined. zp(1) = z(2); "

1 次查看(过去 30 天)
%apple solver code
x0=1e-6; %initial position
xp0=0; %initial velocity
y0=1e-6; %initial position
yp0=0; %initial velocity
tspan=[0 1e-4 0.296];
z0 = [1e-6; 0; 1e-6; 0];
[t,z] = ode45('apple',tspan,z0);
plot(t,z(:,1));
grid on
%%function for solver
function zp = apple(t,z)
m = 20; %%mass of shaft in Newton
k = 170e6; %%stiffness of bearing (k^inner = k^outer)
Pd = 20e-6; %%diametral clearance of ball bearing
tp = 0.296; %%time period
s=13; %%Number of balls
wc = 21.26; %%speed of bearing cage in rad/sec for 500rpm
si = 0; %%angular location of defect on race of bearing
phi0 = 0; %%initial position of ith ball
for t =0 : 1e-2: tp %time increment
for i = 1:1:s; %%ball increment
phi(i) = 2*pi*i/s + wc * t + phi0; %%calculation of ith ball angle
c = Pd/2 * (1 - cos(phi(i))); %%calculation of radial clearance
if phi(i) == si %%condition for ball in region of defect
b = 1;
delta = 1.0586e-2; %%additional deflection of ball when it passes through defect
else
b = 0; %%non-defective region
end
%solving Equation of motion for specified time period using
%Runge Kutta method (ode45)
%converting higher order equations into first order
zp=zeros(4,1);
zp(1)=z(2);
zp(2)=(k*cos(phi(i))/m) * ((z(1)*cos(phi(i)) + z(3)*sin(phi(i)) - b*delta - c)^(3/2) - (z(1)*cos(phi(i)) + z(3)*sin(phi(i)) - b*delta)^(3/2)); %%((a - c)^(3/2) - (a)^(3/2)
zp(3)=z(4);
zp(4)=(k*sin(phi(i))/m) * ((z(1)*cos(phi(i)) + z(3)*sin(phi(i)) - b*delta - c)^(3/2) - (z(1)*cos(phi(i)) + z(3)*sin(phi(i)) - b*delta)^(3/2));
end
end
end

回答(1 个)

Walter Roberson
Walter Roberson 2016-4-13
Try changing to
[t,z] = ode45(@apple,tspan,z0);
and remember that you need to run apple_solver rather than apple
  2 个评论
Walter Roberson
Walter Roberson 2016-4-13
Your code only defines delta when phi(i) == si .
The filename you used when you attached was apple[1].m . The filename would have to be apple.m for MATLAB to be able to find the code. You might find you already have a different apple.m that is being invoked.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by