Jump to content
Tprog

Duvida Classes

Recommended Posts

Tprog

Boa noite, tenho um trabalho no ambito de uma cadeira de mestrado. E é necessario criar uma classe para o modelo SolowSwan que permita gerar séries temporais. a funçao desse modelo è a seguinte:

Kt+1=s*Kt*Wt+1+(1-delta)*Kt

A Wt provem de uma funçao lognormal.

Consigo criar uma classe que permite gerar numeros aleatorios (usando a bilbioteca gsl), mas quando quero ir buscar o valor dado, nao consigo implementar na classe do modelo.

A minha duvida é na classe SolowSwan, aqui fica o codigo

#include <cstdlib>
#include <iostream>
#include <vector>
#include <cmath>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>

using namespace std;
class StatBox {
		private:
			gsl_rng *r;
		public:
			StatBox(size_t seed=1)
			{
				r=gsl_rng_alloc(gsl_rng_mt19937);
				gsl_rng_set(r,seed);	
			}
			~StatBox() {gsl_rng_free(r);}
		   double gerarlognormal(double mu, double sigma) {return gsl_ran_lognormal (r,mu,sigma);}
};

class SolowSwan {
		private:
			size_t t;
			vector <double> K;
			double s;
			double delta;
			double sigma;
			double alpha;
			double K0;
			double mu;
		public:
			SolowSwan(size_t T, double sn,double deltan,double sigman,double alphan,double K0n,double mun)
			{t=T;
			s=sn;
			delta=deltan;
			sigma=sigman;
			alpha=alphan;
			K0=K0n;
			mu=mun;
			}

			double gerarserie() {

					StatBox caixa;

					for (int i=0;i<=t;i++){

					K.push_back(s*K[i-1]*(caixa.gerarlognormal(mu,sigma)+(1-delta)*K[i-1]);
				   } }
};
 

Share this post


Link to post
Share on other sites
HappyHippyHippo

a formula usada como argumento da chamada da função push_back não parece ser igual à dada : Kt+1=s*Kt*Wt+1+(1-delta)*Kt


IRC : sim, é algo que ainda existe >> #p@p

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.