How to plot a complicated function
Afficher commentaires plus anciens
How to plot a complicated equation
-(r * x / K) + (alpha ^ 2 * (1 - c) ^ 2 * x * y / (1 + alpha * h * (1 - c) * x) ^ 2 * h) + d - d * exp(-2 * tau)=0
where x=d /(alpha*(-theta + d*h)*(-1 + c)); y=r*(K-x)*(-1-alpha*h*x+alpha*h*x*c)/(-1 + c)*K*alpha;
The other parameter values are: r=3.3;K=898;alpha=0.045;d=1.06;h=0.0437;theta=0.215;
I have to plot a tau vs c curve such that tau is varying from 0 to 1.6 & c is varying from 0 to .9. I have used the following code
r=3.3;K=898;alpha=0.045;d=1.06;h=0.0437;theta=0.215;
x=d /(alpha*(-theta + d*h) / (-1 + c));
y=r*(K-x)*(-1-alpha*h*x+alpha*h*x*c)/(-1 + c)*K*alpha;
yourfun=@(tau,c) -(r * x / K) + (alpha ^ 2 * (1 - c) ^ 2 * x * y / (1 + alpha * h * (1 - c) * x) ^ 2 * h) + d - d * exp(-2 * tau)
plot(yourfun)
I am getting a problem here and please help me to solve it, please.
Réponse acceptée
Plus de réponses (1)
Youssef Khmou
le 15 Avr 2013
Modifié(e) : Youssef Khmou
le 15 Avr 2013
hi,
the vector x depends on the value c too, same as y , so they are also anonymous functions, in this case you have three anonymous functions with hierarchy yourfun[x(c),y(c),tau] , yourfun is built on tau, x and y and x,y are built on c , you have to make three functions, and when you try to plot function, you wont see a result because you are giving only scalar values like yourfun(4,5) that is only a point in 2d space , to get the result you need to supply two vectors c and tau and they must be of same length :
r=3.3;
K=898;
alpha=0.045;
d=1.06;
h=0.0437;
theta=0.215;
x=@(c) d./(alpha.*(-theta+d*h)./(-1+c));
y=@(c) r*(K-x(c)).*(-1-alpha*h*x(c)+alpha*h*x(c).*c)./(-1+c)*K*alpha;
yourfun=@(tau,c) -(r.*x(c)./K)+(alpha.^2.*(1-c).^2.*x(c).*y(c)./(1+alpha.*h.*(1-c).*x(c)).^2*h)+d-d.*exp(-2*tau)
tau=(0:0.1:1);
c=linspace(0,pi,length(tau));
F=yourfun(tau,c);
plot(F), grid on
figure,plot3(tau,c,F), grid on,view(-12,38)
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!