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 个评论
回答(1 个)
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
2017-10-24
Edit: changed incorrect reference to "inline function" to correct reference to "anonymous function", with hyperlink.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!