If you actually indented your code (consistently), it would make it much easier for you to identify the mistake which is causing this (and then uncover the subsequent errors).
First thing, look around the line where the problem occurs:
Code:x = 0;
end
end
if (V(in) = vh)
You have two successive end statements. The second of these is closing the begin associated with the
analog statement. So it shouldn't be there.
Having fixed that, you have some other issues
Code:if (V(in) = vth)
You've used an assignment rather than an equality check (==) in this statement. That said, using an equality check is not a good idea, because you would be attempting to compare a solved floating point number with a floating point constant. You should never do equality checks on floating point numbers (in pretty much any language) and even more so when one of them is numerically solved. You should check within a tolerance. I would suggest either doing:
Code:if (abs(V(in)-vh)<1e-3)
i.e. give a tolerance on the comparison. Or maybe even:
Code:if (V(in) >= vh)
y = ratioone;
else if (V(in) <= vl)
y = ratiotwo;
else
y = 0;
Note also that I changed the
elseif to
else if because that's also incorrect.
I didn't check the correctness of the model itself. Looks simple enough.
Regards,
Andrew.