|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Jun 2001
Città: Treviso
Messaggi: 1156
|
Mi aiutate a capire ...
... facendo un esempio, come funziona questo programma?
*SONO DATI:UN POLINOMIO DI GRADO N IN X,UN POLINOMIO DI PRIMO GRADO *DEL TIPO X-P *IL PROGRAMMA CALCOLA:IL VALORE DEL POLINOMIO PER UN ASSEGNATO X=M, *I COEFFICIENTI E IL RESTO DEL POLINOMIO DI GRADO N-1 QUOZIENTE DEI *POLINOMI DATI INTEGER N,A(100),C(100),B,P,M,PXD *introdurre i coefficienti a partire da quello della x di primo grado *a quello della x di grado n WRITE(*,*)'INTRODUCI N,A(N),IL TERM.NOTO B,P,X=M' READ(*,*) N,(A(I),I=1,N),B,P,M PXD=B DO 30 I=1,N PXD=PXD+A(I)*M**I 30 CONTINUE WRITE(*,100) PXD K=N C(K)=A(K) DO 10 K=N,1,-1 C(K-1)=C(K)*P+A(K-1) 10 CONTINUE R=C(1)*P+B DO 20 K=N,1,-1 WRITE(*,60) C(K) 20 CONTINUE 100 FORMAT(2X,'VALORE DEL POLINOMIO PER X=M:',I5) WRITE(*,61) R 60 FORMAT(/.3X,I5) 61 FORMAT(/,3X,'IL RESTO VALE:'F7.2) STOP END Cioè, guardate le prime righe. Non ho capito bene. Io metto dentro un polinomio di grado n, e ne ho uno di primo grado. Lui che fà?
__________________
Non ho niente altro da offrire alle altre persone, se non la mia stessa confusione something cold is creepin' around, blue ghost is got me, I feel myself sinkin' down L'arte non insegna niente, tranne il senso della vita |
|
|
|
|
|
#2 | |
|
Senior Member
Iscritto dal: Nov 2002
Città: Singularity
Messaggi: 894
|
Quote:
In poche parole, prende un polinomio P(X), un Q(x) = (x-P) e: 1) valuta P(M). 2) calcola P(x)/Q(X) con relativo resto R Per i dettagli vedo il resto del post INTEGER N,A(100),C(100),B,P,M,PXD Dichiara tutte le variabili usate. Attenzione perchè non accetta polinomi di grado maggiore di 100 WRITE(*,*)'INTRODUCI N,A(N),IL TERM.NOTO B,P,X=M' READ(*,*) N,(A(I),I=1,N),B,P,M Chiede a schermo rispettivamente il grado, i coefficienti del polinomio compreso il termine noto b, il valore del termine noto P del polinomio Q(x), un valore M. PXD=B DO 30 I=1,N PXD=PXD+A(I)*M**I 30 CONTINUE WRITE(*,100) PXD Calcola P(x) in x=M con un ciclo, sommando il termine I-esimo (a_i*x^i) ad ogni iterazione e partendo dal termine noto B. C(K)=A(K) DO 10 K=N,1,-1 C(K-1)=C(K)*P+A(K-1) 10 CONTINUE R=C(1)*P+B Calcola il quoziente della divisione P(x)/Q(x) usando il metodo di Ruffini: si prende il coefficiente più alto, si moltiplica per P, e si somma al coefficiente del polinomio da dividere. DO 20 K=N,1,-1 WRITE(*,60) C(K) 20 CONTINUE Infine scrive a schermo il risultato.
__________________
echo 'main(k){float r,i,j,x,y=-15;while(puts(""),y++<16)for(x=-39;x++<40;putchar(" .:-;!/>"[k&7])) for(k=0,r=x/20,i=y/8;j=r*r-i*i+.1, i=2*r*i+.6,j*j+i*i<11&&k++<111;r=j);}'&>jul.c;gcc -o jul jul.c;./jul |Only Connect| "To understand is to perceive patterns" Isaiah Berlin "People often speak of their faith, but act according to their instincts." Nietzsche - Bayesian Empirimancer - wizardry |
|
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Jun 2001
Città: Treviso
Messaggi: 1156
|
fortran77
grazie, mi sei stato di aiutissimo!!!!
__________________
Non ho niente altro da offrire alle altre persone, se non la mia stessa confusione something cold is creepin' around, blue ghost is got me, I feel myself sinkin' down L'arte non insegna niente, tranne il senso della vita |
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Jun 2001
Città: Verona
Messaggi: 8698
|
mi dai una mano a capire anche il mio? grazie :D
integer a(10,10),sommapa,sommadi
write(*,*)'QUESTO PROGRAMMA ESEGUE LE SOMME DELLE COMPONENTI' write(*,*)'DI POSTO PARI E LE SOMME DELLE COMPONENTI DI' write(*,*)'POSTO DISPARI DI UNA MATRICE' write(*,*)'Introduci N,M e gli elementi di A per colonne.' write(*,*)'Nota:N sono le righe,M le colonne.' read(*,*) m,n,((a(i,j),i=1,m),j=1,n) write(*,*) 'Matrice A introdotta' do 5 i=1,m write(*,50) (a(i,j),j=1,n) 5 continue sommapa=0 sommadi=0 do 10 i=1,n do 10 j=1,m if((int(i+j)/2)*2.eq.(i+j)) then sommapa=sommapa+a(i,j) else if((int(i+j)/2)*2.ne.(i+j)) then sommadi=sommadi+a(i,j) end if 10 continue write(*,60) sommapa,sommadi 60 format(1x,'La somma delle componenti di A di posto pari *vale',i5,1x,'quelle dispari vale ',i5) 50 format(1x,10i5) stop end
__________________
You have to be trusted by the people that you lie to / So that when they turn their backs on you / You'll get the chance to put the knife in |
|
|
|
|
|
#5 | |
|
Senior Member
Iscritto dal: Nov 2002
Città: Singularity
Messaggi: 894
|
Quote:
La parte del codice importante è quella che ho quotato. Per verificare se un elemento è in posto dispari, somma gli indici e verifica che dividendo prima e moltiplicando poi il numero per 2 si ottenga lo stesso numero. Se il numero è dispari in questa sequenza di operazioni si perde il resto e quindi si ottiene un risultato diverso. Per le somme usa la solita tecnica ad accumulatore: prende una variabile inizializzata a 0 e somma i termini ad ogni ciclo.
__________________
echo 'main(k){float r,i,j,x,y=-15;while(puts(""),y++<16)for(x=-39;x++<40;putchar(" .:-;!/>"[k&7])) for(k=0,r=x/20,i=y/8;j=r*r-i*i+.1, i=2*r*i+.6,j*j+i*i<11&&k++<111;r=j);}'&>jul.c;gcc -o jul jul.c;./jul |Only Connect| "To understand is to perceive patterns" Isaiah Berlin "People often speak of their faith, but act according to their instincts." Nietzsche - Bayesian Empirimancer - wizardry |
|
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: Jun 2001
Città: Verona
Messaggi: 8698
|
grazie!!!!!
__________________
You have to be trusted by the people that you lie to / So that when they turn their backs on you / You'll get the chance to put the knife in |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 09:12.



















