MATLAB: How to plot a complicated function

ezplotfunctionplot

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.

Best Answer

It is the same code you wrote, only add loops over c and tau, and use the function (ezplot) to plot a function handle. And DO NOT use (plot) command to plot functions. So try this
clc
clear
close all
r=3.3;
K=898;
alpha=0.045;
d=1.06;
h=0.0437;
theta=0.215;
for c=0:0.1:0.9
for tau=0:0.1:0.6
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);
ezplot(yourfun)
title( {'\tau is ';num2str(tau);'c is ';num2str(c)} )
pause(0.01)
end
end