??? Error using ==> events Too many input arguments.
古いコメントを表示
Hi I am running a file (RP3.m) to solve a differential equation. This file uses the function file (zdot3.m) to get the derivative and another events file (events.m) to identify the event to stop the program. I am getting the following error when I run the file. This has started after the introduction of the events file.
PLEASE HELP
TIA
The 3 files are given below
--ERROR MESSAGE--
??? Error using ==> events
Too many input arguments.
Error in ==> odeevents at 29
eventValue =
feval(eventFcn,t0,y0,eventArgs{:});
Error in ==> ode45 at 207
[haveEventFcn,eventFcn,eventArgs,valt,teout,yeout,ieout]
= ...
Error in ==> RP3 at 21
[t z] = ode45(@zdot3, tspan, z0,
options, p);
------------------------------
The 3 files are given below :
File 1 - RP3.m
% time span based on bubble natural frequency - for Ro = 10 mm, tspan = 9900
% microsec
% tspan = [0 105e-6]; z0 = [0.01 ; 0]
tspan = [0 500e-6]; z0 = [10e-3 ; 0] % z0(1)=Initial buuble radius, m
% z0(2) = Initial bubble velocity, m/s
options = odeset('stats', 'on', 'outputfcn', 'odeplot', 'Events', @events);
gamma = 1.33;
sig = 0.0725; % Surface tension
pvp = 2330;
patm = 1*10^5;
pa = 70000;
w = 31700;
mu = 1e-3; % Viscosity (kg/ms) of water from EXERC IN ADVANC COMP MECH
R0 = 10e-3 ; % Initial bubble radius in metres
%p = zeros(8,1);
p(1) = w; p(2) = pa; p(3) = patm; p(4)= gamma; p(5) = sig;
p(6) = pvp; p(7) = mu; p(8) = R0;
[t z] = ode45(@zdot3, tspan, z0, options, p);
x = z(:, 1); y = z(:, 2);
subplot(1,3,1); plot(t,x)
xlabel('time'); ylabel('Radius');
subplot(1,3,2); plot(t,y)
xlabel('time'); ylabel('Velocity');
subplot(1,3,3); plot(y.*t/0.01, x./0.01)
xlabel('Ut/R0'); ylabel('R/R0');
File 2 - zdot3.m
function rdot = zdot3(t, z, p)
w = p(1); pa = p(2); p0 = p(3); gamma = p(4); sig = p(5);
pvp = p(6); mu = p(7); R0 = p(8);
A = 1*10^5 + pa*sin(w*t) ; % A = p0 + pinf *sin(wt)
pg0 = p0 - pvp + 2*sig/R0; % pg0 = patm - pvp + 2*sig/R
B = pg0 * (z(1) / R0)^(3*gamma);
C = 4*mu*z(2)/z(1);
D = 2*sig/z(1); % ST of water from EXERC IN ADVANC COMP MECH
rdot = [z(2); (-3/2*z(2)^2 + pvp - A+B-C-D)/z(1)];
end
File 3 - events.m
function [eventvalue, stopthecalc eventdirection] = events(t, z)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
R = z(1);
Rdot = z(2);
eventvalue = R/10e-3 - 0.01;
stopthecalc = 1;
eventdirection = -1
end
==================================================
採用された回答
その他の回答 (1 件)
Sreedhar
2014 年 6 月 22 日
0 投票
4 件のコメント
Star Strider
2014 年 6 月 22 日
Since all your variables are already defined in your workspace, and z(:,1) is a vector, to get B in your workspace, simply calculate it there:
B = pg0 * (z(:,1) / R0)^(3*gamma);
Sreedhar
2014 年 6 月 22 日
Star Strider
2014 年 6 月 22 日
(See Comment to my Answer.)
Qiaoli Ji
2017 年 11 月 15 日
Hi, I have met the same question to you. I used the method (nested function) of Hayes and it works. But when I try to used the above link that add p to event function, the matlab told me that the zdot3 function had too less input arguments. Could you help me? Thanks very much.
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!