problem failure file

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

problem failure file

Robert Setif
   Good morning.
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

Thank you very much.
Best regards
FRANCE


Reply | Threaded
Open this post in threaded view
|

Re: problem failure file

karl
Am 21.02.19 um 10:16 schrieb Robert Setif:
   Good morning.
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

Thank you very much.
Best regards
FRANCE


    

Maybe, if there would be a hint, what you do not understand, somebody might be able to help you.



Reply | Threaded
Open this post in threaded view
|

Re: problem failure file

Francesco Potortì
In reply to this post by Robert Setif
>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

You should tell us what is the problem and what you do not understand.

If you run it and get an unexpected result or an error, you should copy
and paste what you see on the command window (text, no image) and tell
us what you expected instead.

--
Francesco Potortì (ricercatore)        Voice:  +39.050.621.3058
ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107
via G. Moruzzi 1, I-56124 Pisa         Skype:  wnlabisti
(entrance 20, 1st floor, room C71)     Web:    http://fly.isti.cnr.it


Reply | Threaded
Open this post in threaded view
|

Re: problem failure file

mmuetzel
In reply to this post by Robert Setif
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 | Threaded
Open this post in threaded view
|

Re: problem failure file

mmuetzel
Yet again: Please keep the mailing list in CC.

I think I answered the same questions in the response to your previous message. Please read below.
If you still have more specific questions, please do ask them.
 
 
Am 23. Februar 2019 um 09:17 Uhr schrieb "Robert Setif":

> Hello! and thank you.
> I write in English and you also answer to me in Englih: 
> I understand English but unfortunately speak it.
> Here is the file "dfac.m" joined  and what Octave answer:
>
> " >> dfac1
> warning: function name 'dfac' does not agree with function 
> filename 'C:\Users\Robert\NEWPROG\Octave\dfac.m'
>  
> error: 'n' undefined near line 5 column 6
> error: called from
>     dfac1 at line 5 column 2  "
> but dfac(10)-> 3840  dfac(11)-> 10395 Ok
> I can't program dfac([1:10]).
> Unfortunately I am not able to vectorize that function.
> Would you correct my file, please? 
> That is not urgent. I am patient.
> Thank you very much and best regards.
> Robert SETIF  France
> [hidden email][mailto:[hidden email]]
>   
>
> Le ven. 22 févr. 2019 à 18:33, "Markus Mützel" <[hidden email][mailto:[hidden email]]> a écrit :
> 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.