Emanuele
Emanuele

Reputation: 2384

Parse error at '[' : usage might be invalid MATLAB syntax

I am developing a small utility that calculates partial differential equation in MATLAB. I am receiveing an error of invalid syntax:

Parse error at '[' : usage might be invalid MATLAB syntax in the function call, but I don't understand why:

Below the code I am using for the main_routine.m:

% pde operations ..

 % Explicit (nonstiff) integration
if(mf == 1)
    [t,u] = ode45(@pde_1, tout, u0, options);
end

%
% Implicit (sparse stiff) integration
if(mf == 2)
    S = jpattern_num;
    options = odeset(options, 'JPattern', S)
    [t,u] = ode15s(@pde_1, tout, u0, options);
end

Function call to jpattern_num.m where the error is:

function S = jpattern_num
global n

% Set independent, dependent variables for the calculation
% of the sparsity pattern
tbase = 0;
for i=1:n
    ybase(i) = 0.5;
end
ybase = ybase';
%
% Compute the corresponding derivative vector
ytbase = pde_1(tbase,ybase); 
fac[];   % <-- Error Here but don't know wy
thresh = 1e-16;
vectorized = 'on';
[Jac,fac] = numjac(@pde_1, tbase, ybase, ytbase, thresh, fac, vectorized);
%
% Replace nonzero elements by "1" (so as to create a "0-1" map of the 
% Jacobian matrix)
S = spones(sparse(Jac));
%
% Plot the map ….

What I tried so far:

1) I thought that it was just an array declaration problem but the error persists. I looked at the official documentation to double check possible discrepancies but I could not find the error.

2) This source was very useful as the user had a similar project. I applied the same modification:

from

fac[];

I applied

fac();

But that didn't solve the problem unfortunately.

3) I dug more into the possible cause of the problem and came across this source, which always from official documentation. I applied what was advised but still the problem persists.

Please, if anyone had a similar problem, advise on how to sole this issue and guide to the right direction.

Upvotes: 1

Views: 841

Answers (1)

JAC
JAC

Reputation: 466

The line as it is now, is not creating an array. If you want to create an empty array, try

fac = [];

But the question is now, why passing an empty array to numjac? If the array will be created in the latter function, there is no need to pass it as an argument. In fact, if an array passed as an argument is modified in the function, Matlab creates a new array.

Upvotes: 2

Related Questions