This question already exists:
Error using symengine>#()0.0 Too many input arguments
Closed 3 years ago.
Exact error is:
Error using symengine>#()0.0
Too many input arguments.
Error in bdipuniodefun (line 18)
bdip = [s(4); s(5); s(6); (q/m_e)*(Ex(s(1),s(2),s(3)) + s(5)*Bz(s(1),s(2),s(3)) - s(6)*By(s(1),s(2),s(3))); (q/m_e)*(Ey(s(1),s(2),s(3)) +
s(6)*Bx(s(1),s(2),s(3)) - s(4)*Bz(s(1),s(2),s(3))); (q/m_e)*(Ez(s(1),s(2),s(3)) + s(4)*By(s(1),s(2),s(3)) - s(5)*Bx(s(1),s(2),s(3)))];
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode15s (line 150)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in collisions6 (line 219)
[T,S] = ode15s(#bdipuniodefun, tspan, icv);
So we know where the error occurs, but I have been unable to resolve it nonetheless. This is an error that has also been inconsistent too. It does not always appear when I run the main script "collisions.m" but happens only when certain things get altered. Some examples: I start with too many electrons/particles, usually 1000+. Or I try to input a non-zero electric field. The electric field function is still being referenced but it is zero (Here comes the strange part). The reason I did this is because although the error goes away, the ode solver does not compute even close to the correct solutions I am looking for. I know for a fact that the results are wrong due to my knowledge of physics. However, when it does this, it does not give an error.
A Matlab staff member suggested that it may have something to due with my persistent variable definition but that is the only possible lead I have.
Troubleshooting methods I have already been through:
First if you look at the documentation from Matlab, it shows a specific syntax example to define the set of ODEs. In Matlab's syntax, they define each equation individually and then the vector of equations using the definitions. When I tried this syntax, the solver either did not solve the equations correctly, or it gave me the "too many input arguments" error. The way I made it run at all was to define every equation outright on a single line in "bdipodefun.m". Only that syntax worked and there is no good reason in my mind why this is the case because the definition that is used in one of the input arguments for the solver is the same. Using the Matlab recommended syntax even in simpler code, makes the ode solution incorrect.
I tried all ode solvers Matlab has to offer. The same issues persist or it cannot solve the equations at all.
I tried re-coding the entire simulation from scratch. I have found that this error still occurs even in more simpler codes.
Equation solver will also not solve the system correctly if there is no E-field. I found that if I create an E-field function and even just define it as zero within the file, the system solves correctly. It absolutely makes no sense as to why this is occurring.
Here is a description of what each file does in the code:
"collisionsmain.m" = Main script that references other files
"B_test.m" = B field function file referenced by collisionsmain
"E_test.m" = E field function file referenced by collisionsmain
"engen.m" = Generates energies for electrons based on a Maxwellian probability distribution curve
"maxdis.m" = Maxwellian distribution function used by engen
"engen.m" = Generates energies for electrons based on a Maxwellian
"posgen.m" = Generates a random, initial position on a sphere "bdipodefun.m" = ODE function set referenced by ODE solver in collisionsmain
Link to files: https://drive.google.com/drive/folders/19eJrgWYL4LQFwTY-VwguCCkta-pimZlL?usp=sharing
I didn't understand the code because it is complicated and big. Anyway, I tracked the error and find the source of the issue. The error comes from the number of parameters that have been sent to Ex, Ey, Ez in bdipuniodefun.m function. Ex, Ey, Ez functions receives 3 parameters while they can handle one parameter only.
The following code didn't send error and it shows the results.
bdip_r1 = [s(4); s(5); s(6)];
bdip_r2 = (q/m_e) * (Ex(s(1)) + s(5)*Bz(s(1),s(2),s(3))- s(6)*By(s(1),s(2),s(3)));
bdip_r3 = (q/m_e)*(Ey(s(1)) + s(6)*Bx(s(1),s(2),s(3)) - s(4)*Bz(s(1),s(2),s(3)));
bdip_r4 = (q/m_e)*(Ez(s(1)) + s(4)*By(s(1),s(2),s(3)) - s(5)*Bx(s(1),s(2),s(3)));
bdip =[bdip_r1;bdip_r2;bdip_r3;bdip_r4];
Related
I am trying to run a repeated measures ANOVA in Matlab with 4 factors including one factor representing my subjects which I want as a random factor.
The code I have is as follows:
[p,table,stats] = anovan(COORDS_SUBJ_II,{group_hand,group_stim,group_time,group_subs},'random',4,'varnames',{'HAND','STIM','TIME','SUBS'});
Here, all variables have the same dimension, which is 1350x1(all types are 'double'). I checked my code with some proposed code on the net and it matches, yet I keep getting the following error...
Error using chi2inv (line 3)
P and V must be of common size or scalars
Error in anovan>varcompest (line 838)
L = msTerm .* dfTerm ./ chi2inv(1-alpha/2,dfTerm);
Error in anovan>getRandomInfo (line 811)
[varest,varci] = varcompest(ems,randomterms,msTerm,dfTerm,alpha);
Error in anovan (line 296)
getRandomInfo(msterm,dfterm,mse,dfe,emsMat,randomterm,...
My dependent variable (COORDS_SUBJ_II) has a couple of NaN's in it, although I ran the code once where I replaced those NaN's with random numbers and it still gives me the same error. I am kind of lost right now and would appreciate any help.
Best
ty
Found it out. A toolbox I downloaded a while ago also had the chi2inv command and this prompted the error =)
I am using MATLAB R2015 and cannot implement 'butter' without getting an error related to too many output arguments from the polyfit part of the script. I have used the same implementation for years with other versions of MATLAB.
Example:
[b, a] = butter(2,[.15,.3]);
Error using poly
Too many output arguments.
Error in zp2ss (line 127)
den = real(poly(p(i:i+1)));
Error in butter (line 97)
[a,b,c,d] = zp2ss(z,p,k);
I get the same error implementing the examples in the help documentation.
Just a guess but is there any chance you've defined your own poly function? which('poly') should point to some Matlab directory unless you've defined it elsewhere, potentially as a variable?. For me on a newer version that path is something like $MATLAB/toolbox/matlab/polyfun/poly.m You can also edit the poly function edit poly and verify that there is one output argument for the function.
Also, I'd advise against ever writing decimal numbers without a leading zero. It took me way to long to figure out what [.15,.3] was. Instead write [0.15,0.3] or even just [0.15 0.3] Edit: I just realized that is an example in Matlab ... my point stands but the toolbox author should know better ...
As part of a group project we have a system of 2 non linear differential equations and we have to draw the S=S(t) , I=I(t) graphic using the midpoint method.
And I'm getting the following error when trying to insert the matrix with the corresponding differential equations:
"Error in inline expression ==> matrix([[-(IS)/1000], [(IS)/1000 - (3*I)/10]])
Undefined function 'matrix' for input arguments of type 'double'.
Error in inline/subsref (line 23)
INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr, INLINE_OBJ_.expr);"
The code I have done is the following:
syms I S
u=[S;I];
F=[-0.001*S*I;0.001*S*I-0.3*I];
F1=inline(char(F),'I','S');
h=100; %Valores aleatórios
T=100000;
ni=(T/h);
u0=[799;1];
f=zeros(1,2);
k=zeros(1,2);
i=1;
while i<=ni
f(1)=F1(u0(1));
f(2)=F1(u0(2));
dx=h*f;
k(1)=F1((u0(1)+h*(1/2)),(u0(2)+h*(1/2)));
k(2)=F1((u0(1)+h*(1/2)),(u0(2)+h*(1/2)));
u1=u0+h*k;
disp('i:'),disp(i)
disp('u= '),disp(u1)
u0=u1;
i=i+1;
end
I'm new to this so the algorithm it's very likely to be wrong but if someone could help me with that error I'd apreciate it. Thank you!
The problem that specifically creates the error is that you are putting two symbolic functions into a matrix and then calling char (which outputs matrix([[-(IS)/1000], [(IS)/1000 - (3*I)/10]]) rather than converting nicely to string).
The secondary problem is that you are trying to pass two functions simultaneously to inline. inline creates a single function from a string (and using anonymous functions instead of inline is preferred anyway). You cannot put multiple functions in it.
You don't need sym here. In fact, avoid it (more trouble than it's worth) if you don't need to manipulate the equations at all. A common method is to create a cell array:
F{1} = #(I,S) -0.001*S*I;
F{2} = #(I,S) 0.001*S*I-0.3*I;
You can then pass in I and S as so:
F{1}(500,500)
Note that both your functions include both I and S, so they are always necessary. Reconsider what you were expecting when passing only one variable like this: f(1)=F1(u0(1));, because that will also give an error.
I'm evaluating a series of theoretical (not necessarily functional) circuits in matlab. I have been trying to get the transfer function of the circuits and during the process I use the sym2poly function. Sometimes, sym2poly works and returns the transfer function. Sometimes it does not.
This is what the code looks like:
[n,d] = numden(eval(v_3/V));
transH = tf(sym2poly(n),sym2poly(d))
n and d are symbolic cell arrays. The error I get is:
Error using sym/sym2poly (line 28)
Not a polynomial.
Error in CircuitGA (line 349)
n = sym2poly(n);
This looks similar to several questions posted a long time ago, but all of those were solved by a bug fix in an updated version of the symbolic math toolbox. Does it mean that what I am giving it is impossible to turn into a polynomial?
Is there a fix?
Any suggestions of a method that will work for all my circuit arrays?
Maybe a try and catch for if it can return a transfer function?
I am having problem when I try to store rmabackadj function's output to a variable. The function works properly when no output variable is assigned. This function is part of bioinformatics toolbox.
So the issue is when I try to run the following it works properly:
rmabackadj(myprobeData.PMIntensities)
But when I try to run the following I get an error:
>> A = rmabackadj(myprobeData.PMIntensities)
Warning: Colon operands must be real scalars.
> In rmabackadj>findMaxDensity at 255
In rmabackadj at 164
Error using ksdensity>parse_args (line 162)
X must be a non-empty vector.
Error in ksdensity (line 114)
[axarg,yData,n,ymin,ymax,xispecified,xi,u,m,kernelname,...
Error in rmabackadj>findMaxDensity (line 255)
[f, x] = ksdensity(z, min(z):(max(z)-min(z))/npoints:max(z), 'kernel', 'epanechnikov');
Error in rmabackadj (line 164)
mu = findMaxDensity( o(o < mu));
I searched for it online as well, but I couldn't find any result. Does anybody have any idea about the cause of this error?
PS: When I assign ans variable to a new variable, it is properly assigned.
A = ans
I'm pretty sure this is a bug.
Firstly, the reason it errors only when you supply an output argument is because there's an internal switch in the function that calculates different things based on nargout. That's an odd design, but not necessarily a bug.
Internal to rmabackadj there are two subfunctions findMaxDensity and findMaxDensity2. The main routine calls findMaxDensity, which is supposed to find an initial guess for the parameter mu. However (when I run the documentation example that you mention in your comment), it finds a terrible guess right on the edge, leading to an error.
When I edit the file to call findMaxDensity2 rather than findMaxDensity, it seems to produce a reasonable guess, and runs fine with no error. I can't vouch for whether the guess is actually "correct", but it seems reasonable to me, and it's only functioning as an initial guess to start off a better estimation process. (NB if you do this yourself, make sure to save a copy of the old version first).
I would guess that this is a bug, either that findMaxdensity is generating an unusually poor guess that should be caught, or that really it should be calling findMaxDensity2 and the code has not been updated to call a new subfunction.
Either way, I would report it to MathWorks.
PS I am running MATLAB R2011b. Check first if the issue has been fixed, or behaves differently, in more recent versions.
Mathworks confirmed this bug and issued a work around for it and mentioned this may be fixed in future releases.
One possible workaround is to add the following conditional at line 163 of rmabackadj function
% estimate mu from left-of-the-mode data
if any(o < mu)
mu = findMaxDensity( o(o < mu));
end
The bug for N<1000 samples has been confirmed as well but no work around has been issued yet.
I will update the thread if the work around for N<1000 samples bug.