octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem failure file


From: Markus Mützel
Subject: Re: problem failure file
Date: Fri, 22 Feb 2019 18:33:49 +0100

Please keep the mailing list in CC, so others who might be able to help can 
answer as well.

Am 22. Februar 2019 um 08:47 Uhr schrieb "Robert Setif":
> Hello !
> Thank you for your very fast answer. You find an error: "=" au lieu de "==". 
> Je continue en français. Maintenant c'est ok, presque. Voici le message de 
> Octave:
> "error: 'n' undefined near line 4 column 6
> error: called from
>     dfac at line 4 column 2.
> mais dfac(10) -> 3840
>  Voici 2 questions:
>  1. Cette erreur n'empêche pas de fonctionner. Mais elle est signalée dans 
> presque tous mes programmes. Pourquoi "'n' undefined"  et  comment y remédier 
> ?
Your function "dfac" has one input argument "n". You probably see this error 
because you called the the function without input argument. I haven't tried but 
something like "dfac(5)" should not throw this error.

>  2. Comment faire pour que dfac([1:10]) fonctionne ? Il ya sans doute une 
> autre façon de le faire, mais laquelle ?
Each line of your function must work with "n" as a vector for this to work.
E.g. instead of writing:
if (n==0)
  r=1;
endif

you would write:
r = zeros (size (n)); % initialize r to the same size as n
r(n==0) = 1; % only set those elements in "r" that correspond to n==0

And appropriately for the other conditional branches.

> Thank you very much and best regards. 



> Le jeu. 21 févr. 2019 à 10:55, "Markus Mützel" 
> <address@hidden:address@hidden> a écrit :
> > On 21 Feb 2019 10:16:03 +0100 "Robert Setif" wrote:
> > Here is that file with a problem I do not understand.
> >
> > # dfac.m 21/2/2019  double factorial
> > function r=dfac(n)
> > f=1;
> > if (n=0)
> >   r=1;
> > elseif (mod(n,2)=0)
> >     for i=n:-2:2,f=f*i;,endfor
> > else
> > for i=1:2:n,f=f*i;,endfor
> >   endif
> >  r=f;
> > endfunction
>
> I am not sure what the problem is you see. But you probably want to use the 
> comparison operator "==" instead of the assignment operator "=" in the 
> conditions.
> 
> Markus



reply via email to

[Prev in Thread] Current Thread [Next in Thread]