Effacer les filtres
Effacer les filtres

How can I determine the time and corresponding values of two functions when the value one function is 20% larger than the other one with a FOR oder WHILE loop?

1 vue (au cours des 30 derniers jours)
Hi guys,
I'm new to Matlab and there is a task I don't know how to solve. So I have this code:
Pumax=75E3; % factor in front of exp-term
ku=0.045; % the decay rate
Pumin=1E5;
Psmax=3E5;
Po=1E4;
ks=0.08;
t = [0:1:200]
Ps=Psmax./(1+((Psmax/Po)-1)*exp(-ks*t)); %suburbs
Pu= Pumax*exp(-ku*t) + Pumin ; %city
Now i shall determine the time and corresponding values of Pu(t) and Ps(t) when the population of the suburbs are 20% larger than the city with a for or a while loop.
  1 commentaire
Stephen23
Stephen23 le 23 Oct 2017
Modifié(e) : Stephen23 le 23 Oct 2017
Note that the square brackets are not needed when creating a vector, as you are not concatenating anything. All you need is:
t = 0:1:200;
You will also notice that the MATLAB editor shows a warning saying that the square brackets are not required. See:

Connectez-vous pour commenter.

Réponses (1)

Reza Bonyadi
Reza Bonyadi le 24 Oct 2017
Modifié(e) : Stephen23 le 24 Oct 2017
I would do the following: First, you want x such that Ps(x)=Pu(x)+0.2*Pu(x). So, define an anonymous function:
myf = @(x)(((Psmax./(1+((Psmax/Po)-1)*exp(-ks*x))))-1.2*(Pumax*exp(-ku*x) + Pumin));
This essentially defines the function myf(x)=Ps(x)-(Pu(x)+0.2*Pu(x))
You are then after an x in a way that myf(x) is 0. You can find such x using many methods, such as fzero:
fzero(myf,35)
35 is just a guess for the solution and the function returns 39.6068.
Indeed if you do
a=39.6068;Psmax./(1+((Psmax/Po)-1)*exp(-ks*a))-1.2*(Pumax*exp(-ku*a) + Pumin)
you will get close to zero.
You can see the corresponding values by:
a=39.6068;disp([(Psmax./(1+((Psmax/Po)-1)*exp(-ks*a))) Pumax*exp(-ku*a) + Pumin]);
Does that work?
  1 commentaire
Stephen23
Stephen23 le 24 Oct 2017
Edit: changed incorrect reference to "inline function" to correct reference to "anonymous function", with hyperlink.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by