Trying to plot two equations with ezplot.
5 views (last 30 days)
Show older comments
Hello:
I am trying to plot a pair of simultaneous equations to see at which points they intersect for a given interval 0 to 6pi. The first equation would be plotted in green and the second equation would be plotted in blue.
My code is as follows:
c=input('c');
syms p q
eqn1 =(p^2*q^2*(q^2+p^2)+c^2*(p^4+q^4-6*p^2*q^2)-3*c^4*(p^2-q^2)-4*c^6)*sin(p)*sinh(q)+2*p*q*(-p^2*q^2+3*c^2*(p^2-q^2)-7*c^4)*cos(p)*cosh(q)-p*q*(p^4+q^4+2*c^2*(q^2-p^2)+2*c^4)*cos(2*c)==0;
eqn2 = 2*c*p*(3*p^2*q^2-q^4-c^2*(p^2+q^2)+4*c^4)*cos(p)*sinh(q)+2*c*q*(p^4-3*q^2*p^2-c^2*(p^2+q^2)-4*c^2)*sin(p)*cosh(q)+p*q*((p^2+q^2)*(q^2-p^2+2*c^2))*sin(2*c)==0;
a = axes;
h = ezplot(eqn1);
h.LineColor = 'green';
hold on
grid on
g = ezplot(eqn2);
g.LineColor = 'blue';
L=sym(0:pi:6*pi);
a.PTick = double(L);
a.QTick = double(L);
M = arrayfun(@char, L, 'UniformOutput', false);
a.PTick = M;
a.QTick = M;
title('Plot of System of Nonlinear Equations')
legend('eqn1','eqn2', 'location', 'best')
% code
However, when I run the script, both of my equations come out in the same color: green. For example, when I choose for my input of c to be 1, my plot comes like this:

It seems in all other respects to be running as it should.
Any assistance is appreciated. Thank you in advance.
2 Comments
Star Strider
on 22 Jul 2015
The colours plot correctly for me (in R2015a), but ‘PTick’ is throwing an error. (Neither MATLAB nor I have ever heard of it.)
Answers (0)
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!