Cos'è ElectroYou | Login Iscriviti

ElectroYou - la comunità dei professionisti del mondo elettrico

Problema Matlab con fattoriale

Strumenti informatici per la matematica applicata, le simulazioni, il disegno: Mathcad, Matlab, Scilab, Microcap, PSpice, AutoCad ...

Moderatori: Foto Utenteg.schgor, Foto Utentedimaios

0
voti

[1] Problema Matlab con fattoriale

Messaggioda Foto Utenteireon » 23 dic 2012, 17:04

Se io scrivo in Matlab le seguenti istruzioni:

syms x;
f = (x+1)^x-factorial(x);


Mi appare il messaggio d'errore "N must be a matrix of non negative integers"

Quindi come faccio a scrivere correttamente la funzione?
Avatar utente
Foto Utenteireon
14 1 2 6
Frequentatore
Frequentatore
 
Messaggi: 237
Iscritto il: 24 ott 2010, 12:21

0
voti

[2] Re: Problema Matlab con fattoriale

Messaggioda Foto Utenteg.schgor » 23 dic 2012, 18:45

Prova a definire x come intero e limitarlo ai primi numeri (4 o 5)
Avatar utente
Foto Utenteg.schgor
57,8k 9 12 13
G.Master EY
G.Master EY
 
Messaggi: 16971
Iscritto il: 25 ott 2005, 9:58
Località: MILANO

0
voti

[3] Re: Problema Matlab con fattoriale

Messaggioda Foto UtenteDirtyDeeds » 23 dic 2012, 20:33

Prova con queste dichiarazioni:

Codice: Seleziona tutto
syms x positive;
assumeAlso(x,'integer');
It's a sin to write sin instead of \sin (Anonimo).
...'cos you know that cos ain't \cos, right?
You won't get a sexy tan if you write tan in lieu of \tan.
Take a log for a fireplace, but don't take log for \logarithm.
Avatar utente
Foto UtenteDirtyDeeds
55,9k 7 11 13
G.Master EY
G.Master EY
 
Messaggi: 7012
Iscritto il: 13 apr 2010, 16:13
Località: Somewhere in nowhere

0
voti

[4] Re: Problema Matlab con fattoriale

Messaggioda Foto Utenteireon » 23 dic 2012, 22:28

Mi appare scritto "Undefined function 'assumeAlso' for input arguments of type 'sym'."
Avatar utente
Foto Utenteireon
14 1 2 6
Frequentatore
Frequentatore
 
Messaggi: 237
Iscritto il: 24 ott 2010, 12:21

0
voti

[5] Re: Problema Matlab con fattoriale

Messaggioda Foto Utentedimaios » 24 dic 2012, 11:24

:shock: Sei sicuro di cosa hai scritto ?
Prova a copiare sul workspace queste righe di codice ( cut & paste e premi enter ).

Codice: Seleziona tutto
clear all;
syms x positive;
assumeAlso(x,'integer');
f = (x+1)^x-factorial(x);


A me funziona correttamente.
Ingegneria : alternativa intelligente alla droga.
Avatar utente
Foto Utentedimaios
30,2k 7 10 12
G.Master EY
G.Master EY
 
Messaggi: 3381
Iscritto il: 24 ago 2010, 14:12
Località: Behind the scenes

0
voti

[6] Re: Problema Matlab con fattoriale

Messaggioda Foto Utenteireon » 24 dic 2012, 14:07

Mi appare scritto il messaggio d'errore, posto l'immagine:

Immagine
Avatar utente
Foto Utenteireon
14 1 2 6
Frequentatore
Frequentatore
 
Messaggi: 237
Iscritto il: 24 ott 2010, 12:21

0
voti

[7] Re: Problema Matlab con fattoriale

Messaggioda Foto Utentedimaios » 24 dic 2012, 14:41

Verifica se i comandi esistono nella tua versione di Matlab.
Secondo le release notes di Matlab risulterebbe che ....
R2012a
New Features, Bug Fixes, Compatibility Considerations
expand all
New Special Functions
New Vector Analysis Functions
Computations with Symbolic Functions
Assumptions on Variables

You can set assumptions on symbolic variables by using these functions:

assume sets assumptions on symbolic variables.

assumeAlso adds assumptions on symbolic variables without erasing the previous assumptions.

assumptions shows assumptions set on symbolic variables.

New Relational Operators Create Equations, Inequalities, and Relations
New Logical Operators Create Logical Expressions


Prova a digitare :

Codice: Seleziona tutto
help assumeAlso


e vedi se la funzione esiste nella tua versione di Matlab che dall'immagine risulta essere la 2011b.
Ingegneria : alternativa intelligente alla droga.
Avatar utente
Foto Utentedimaios
30,2k 7 10 12
G.Master EY
G.Master EY
 
Messaggi: 3381
Iscritto il: 24 ago 2010, 14:12
Località: Behind the scenes

0
voti

[8] Re: Problema Matlab con fattoriale

Messaggioda Foto Utenteireon » 24 dic 2012, 15:56

Non esiste nella mia versione, mi appare scritto "assumeAlso not found." Non c'è un altro modo per sottrarre una quantità fattoriale incognita?
Avatar utente
Foto Utenteireon
14 1 2 6
Frequentatore
Frequentatore
 
Messaggi: 237
Iscritto il: 24 ott 2010, 12:21

0
voti

[9] Re: Problema Matlab con fattoriale

Messaggioda Foto Utentedimaios » 24 dic 2012, 16:10

Fai un tentativo con questo :

Codice: Seleziona tutto
syms x positive;
f = (x+1)^x-factorial(round(x));
Ingegneria : alternativa intelligente alla droga.
Avatar utente
Foto Utentedimaios
30,2k 7 10 12
G.Master EY
G.Master EY
 
Messaggi: 3381
Iscritto il: 24 ago 2010, 14:12
Località: Behind the scenes

0
voti

[10] Re: Problema Matlab con fattoriale

Messaggioda Foto Utenteireon » 24 dic 2012, 17:16

Ho risolto con il seguente codice:

syms x;
f = (x+1)^x-sym('n!');
Avatar utente
Foto Utenteireon
14 1 2 6
Frequentatore
Frequentatore
 
Messaggi: 237
Iscritto il: 24 ott 2010, 12:21

Prossimo

Torna a Programmi applicativi: simulatori, CAD ed altro

Chi c’è in linea

Visitano il forum: Nessuno e 2 ospiti