Error: File: slopfield.m Line: 1 Column: 30 Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.

1 visualizzazione (ultimi 30 giorni)
Hi i am working on this code:
function [t,y] = eulode(dxdt,[0,0.4],2,0.1,varargin)
% input:
if nargin<4,error('at least 4 input arguments required'),end
ti = tspan(1);tf = tspan(2);
if ~(tf>ti),error('upper limit must be greater than lower'),end
t = (ti:h:tf)'; n = length(t);
if t(n)<tf
t(n+1) = tf;
n = n+1;
end
y = y0*ones(n,1); %preallocate y to improve efficiency
for i = 1:n-1 %implement Euler's method
y(i+1) = y(i) + dydt(t(i),y(i),varargin{:})*(t(i+1)-t(i));
end
but i keep getting the error "Error: File: slopfield.m Line: 1 Column: 30 Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
  2 Commenti
Peter O
Peter O il 11 Mar 2020
It sounds like slopfield is getting called and there's a syntax error in that file. Is that another function you've created? My hunch would be that the dydt.m function calls it.
Type
edit slopfield
to open it, and see if the MLINT syntax checker highlights a line somewhere.

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 11 Mar 2020
function [t,y] = eulode(dxdt,[0,0.4],2,0.1,varargin)
That is invalid syntax for a function definition. The part in () can only have a list of pure variable names or the special keyword varargin, and can never have constants or indexed variables.
Your code uses variable names tspan and h without defining them.

Categorie

Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by