I'm trying to plot the solution of a non-linear equation, but it's very, very slow. From what I could gather, it's not finding the solution that is time consuming, so I cannot quite understand the reason why the plot takes too long. Anyone has an idea about what may be the problem here?
Clear["Global`*"]
pbase = .5;
sbase = .5;
nbase = .35;
abase = .1;
tbase = .7;
lbase = 1.6;
kbase = .2;
ibase = .01;
y[p_, t_, k_, z_, a_] := p/(1 - t)*k*z*(1 - z/(2*a));
m[p_, t_, k_, z_, a_] := Max[k*z, k*z*(1 - z/(2*a))*(1 + p*t/(1 - t))];
u[p_, t_, k_, z_, a_, n_, l_] :=
p*(l*y[p, t, k, z, a])^(1 - n)/(1 - n) - (1 - p)*
y[p, t, k, z, a]^(1 - n)/(1 - n);
eq[p_, t_, k_, z_, a_, n_, l_, s_, i_] := -i*m[p, t, k, z, a] +
s*(u[p, t, k, z, a, n, l] + (1 - p)*k*z*(1 - z/a) -
m[p, t, k, z, a]);
zsol[p_, t_, k_, a_, n_, l_, s_, i_] :=
z /. NSolve[eq[p, t, k, z, a, n, l, s, i] == 0 && z > 0, z];
ysol[p_, t_, k_, a_, n_, l_, s_, i_] :=
y[p, t, k, zsol[p, t, k, a, n, l, s, i], a];
yprime[p_, t_, k_, z_, a_] := p/(1 - t)*k*(1 - z/a);
uprime[p_, t_, k_, z_, a_, n_, l_] := (1 + p*(l^(1 - n) - 1))*
y[p, t, k, z, a]^(-n);
eq2[p_, t_, k_, z_, a_, n_, l_] :=
uprime[p, t, k, z, a, n, l]*yprime[p, t, k, z, a] -
1 - (1 - p)*k*z/a;
zstar[p_, t_, k_, a_, n_, l_] :=
z /. NSolve[eq2[p, t, k, z, a, n, l] == 0 && z > 0, z];
ystar[p_, t_, k_, a_, n_, l_] :=
y[p, t, k, Evaluate[zstar[p, t, k, a, n, l]], a];
istar[p_, t_, k_, a_, n_, l_, s_] :=
s*((u[p, t, k, zstar[p, t, k, a, n, l], a, n, l] + (1 - p)*k*
zstar[p, t, k, a, n, l]*(1 - zstar[p, t, k, a, n, l]/a))/
m[p, t, k, zstar[p, t, k, a, n, l], a] - 1);
Plot[Evaluate[
ysol[pbase, tbase, kbase, abase, nbase, lbase, sbase, i]], {i,
istar[pbase, tbase, kbase, abase, nbase, lbase, sbase][[1]],
istar[pbase, tbase, kbase, abase, nbase, lbase, sbase][[1]] + .3},
PerformanceGoal -> "Speed"]