フィルターのクリア

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 回表示 (過去 30 日間)
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 件のコメント
Stephen23
Stephen23 2017 年 10 月 23 日
編集済み: Stephen23 2017 年 10 月 23 日
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:

サインインしてコメントする。

回答 (1 件)

Reza Bonyadi
Reza Bonyadi 2017 年 10 月 24 日
編集済み: Stephen23 2017 年 10 月 24 日
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 件のコメント
Stephen23
Stephen23 2017 年 10 月 24 日
Edit: changed incorrect reference to "inline function" to correct reference to "anonymous function", with hyperlink.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by