Interpolazione lineare in VBA

05.10.2013 22:15

In questo Post, vedremo come impostare una semplice funzione di VBA per il calcolo della radice di una funzione f(x) attraverso il metodo dell'interpolazione lineare. 

In generale l'interpolazione lineare considera due punti dati, denotiamoli (xa,ya) e (xb,yb), e assume come funzione interpolante quella definita come

Questa formula può essere interpretata come la media ponderata. 

Facciamo una funzione in excel che ci calcoli direttamente il valore di X in maniera semplice e veloce.

Le nuove funzioni possono essere inserite nella finestra "codice" di un modulo inserendo d'apprima la parola chiave "Function" e successivamente: il nome della funzione; la parentesi tonda aperta; gli eventuali parametri separati da una virgol; la parentesi tonda chiusa; opzionalmente la parola chiave "As" seguita dal tipo di valore da restituire.

Ecco l'esempio

 

Function InterpolazioneLineare(X As Double, Xb As Double, Xa As Double, Yb As Double, Ya As Double) As Double
'funzione di Interpolazione lineare secondo la funzione
'f(x) = \frac{x-x_b}{x_a-x_b} y_a - \frac{x-x_a}{x_a-x_b} y_b.
 
        'dichiaro le variabili da utilizzare nel calcolo
        Dim GenericoX As Double
            
        GenericoX = X
    
        'aggiungo qualche condizione per evitare che il codice si blocchi o vada in errore nel caso di valori errati.
        If Xa = Xb Then
        Exit Function
        ElseIf Xb <= X Then
        Exit Function
        ElseIf Xa >= X Then
        Exit Function
        ElseIf X = "0" Then
        Exit Function
    
    Else
    
    InterpolazioneLineare = (((GenericoX - Xb) / (Xa - Xb)) * Ya) - (((GenericoX - Xa) / (Xa - Xb)) * Yb)
    
    End If
 
End Function
 

 

La funzione, così come concepita, una volta salvata e inserita tra gli add-in disponibili, può essere direttamente richiamata in excel inserendo nella cella:

=InterpolazioneLineare()

 

ed inserendo, all'interno delle parentesi i parametri così come impostati nel codice.

 

 

Argomento: Interpolazione lineare in VBA

Oggetto: How To Prevent Prostate Problems And Diseases? Autore: Albertgring Data: 11.08.2018

The prostate is a vital section of a male's the reproductive system. It secretes fluids that aid in the transportation and activation of sperm. The prostate related is found just in front of the rectum, below the bladder and surrounding the urethra. When there is prostate problem, in most cases very uncomfortable and inconvenient for the patient as his urinary strategy is directly affected.

The common prostate health conditions are prostate infection, enlarged prostate and prostate type of cancer.



Prostate infection, also called prostatitis, is regarded as the common prostate-related condition in men younger than 55 years old. Infections with the prostate are classified into four types - acute bacterial prostatitis, chronic bacterial prostatitis, chronic abacterial prostatitis and prosttodynia.

Acute bacterial prostatitis could be the least common coming from all varieties of prostate infection. It is brought on by bacteria found in the large intestines or urinary tract. Patients may experience fever, chills, body aches, back pains and urination problems. This condition is treated by using antibiotics or non-steroid anti-inflammatory drugs (NSAIDs) to alleviate the swelling.

Chronic bacterial prostatitis is really a condition of the particular defect inside gland along with the persistence presence of bacteria in the urinary tract. It can be a result of trauma on the urinary tract or by infections received from other parts of the body. A patient may experience testicular pain, spine pains and urination problems. Although it is uncommon, it can be treated by removal of the prostate defect as well as the use antibiotics and NSAIDs to help remedy the inflammation.

Non-bacterial prostatitis accounts for approximately 90% of most prostatitis cases; however, researchers have not yet to create what causes these conditions. Some researchers feel that chronic non-bacterial prostatitis occur as a consequence of unknown infectious agents while other believe intensive exercise and heavy lifting can cause these infections.

Maintaining a Healthy Prostate

To prevent prostate diseases, an appropriate weight loss program is important. These are some of the steps you can take and also hardwearing . prostate healthy.

1. Drink sufficient water. Proper hydration is essential for health and wellness and it'll also keep the urinary track clean.

2. Some studies suggest that a number of ejaculations each week will prevent cancer of the prostate.

3. Eat beef sparingly. It has been shown that consuming over four meals of beef per week will increase the risk of prostate diseases and cancer.

4. Maintain an appropriate diet with cereals, vegetable and fruits to make certain sufficient intake of nutrients necessary for prostate health.

The most significant measure to look at to be sure a proper prostate would be to select regular prostate health screening. If you are forty years and above, you need to select prostate examination at least one time 12 months.