Plot symbolic implicit function between two given generic linear functions -or- Find the minimum/maximum value of x and/or y value of a symbolic implicit function
Show older comments
EDIT: I resolved the problem in another way, without symbolic function that seems to me a complication for this simple problems :)
Hi !
I'm trying to roto-translate the plot of a symbolic function from the origin to a pair of points that represent the new origin of the plot and the direction of the x axix, and showing only the respective part of the function between the perpendicular lines to the extreme of the segment (as I would plot the function between two values of x in the standard cartesian plane)
I've had some problems when the line connecting the two points is perfectly orizontal because the perpendicular one has an angular coefficient of infinity (and viceversa).
For easy functions this version of the code plots quite well, as I calculate the value of the function at the two extremities of xy and then rototraslate those points to find the new coordinates that became the limits of plotting for fimplicit(F).
But when the function is a little more complex, the code doesn't work properly because the coordinate of the value of the function at the initial point is greater than some other points in the interval.
I tried (unsuccessuffuly) to resolve this problem with two strategies:
- finding the minimum x coordinate of the implicit symbolic function, given the boundaries of the two lines passing through the points perpendicular to the line connecting the points
- plotting in the range of the fimplicit the implicit equation of the lines
Here's the code so far:
clear all
close all
clc
syms x y l1 l2 l3 l1e l2e f f1 f2 F xn yn
syms xa ya xb yb
X1=1;
Y1=1;
X2=5;
Y2=3;
m=1;
M=10;
k=1; % orientation
% 1: standard xy
% -1: inversed xy
if X1<X2
x1=X1;
y1=Y1;
x2=X2;
y2=Y2;
elseif X2<X1
x1=X2;
y1=Y2;
x2=X1;
y2=Y1;
elseif Y1<Y2
x1=X1;
y1=Y1;
x2=X2;
y2=Y2;
elseif Y2<Y1
x1=X2;
y1=Y2;
x2=X1;
y2=Y1;
end
xx = [x1 x2];
yy = [y1 y2];
p1 = [x1 y1];
p2 = [x2 y2];
l=sqrt((x2-x1)^2+(y2-y1)^2);
n = (y2-y1)/(x2-x1);
th = atan(n);
t = -1/n;
if or(not(n==0),not(t==0))
l1(x,y)=-y+n*(x-x1)+y1; % segment
l2(x,y)=-y+t*(x-x1)+y1; % orth seg
l3(x,y)=-y+t*(x-x2)+y2;
end
if n==0
l1(x,y) = -y+y1;
l2(x,y) = -x+x1;
l3(x,y) = -x+x2;
end
if t==0
l1(x,y) = -x+x1;
l2(x,y) = -y+y1;
l3(x,y) = -y+y2;
end
f1(x,y)=x^3; %FUNCTION TO PLOT
f2(x,y)=-y;
f=k*f1+f2;
xa=0;
ya=double(solve(subs(f,[x,y],[0,y])));
xb=l;
yb=double(solve(formula(subs(f,[x,y],[l,y]))));
xn=cos(th)*(x-x1)+sin(th)*(y-y1);
yn=-sin(th)*(x-x1)+cos(th)*(y-y1);
F=subs(f,[x,y], [xn,yn]);
XA=double(x1+xa*cos(th)-ya*sin(th));
YA=double(y1+xa*sin(th)+ya*cos(th));
XB=double(x1+xb*cos(th)-yb*sin(th));
YB=double(y1+xb*sin(th)+yb*cos(th));
xmin=min((XA),(XB));
xmax=max((XA),(XB));
ymin=min((YA),(YB));
ymax=max((YA),(YB));
% if t==0
% A= -M;
% B= M;
% C= ymin;
% D= ymax;
% elseif n==0
% A= xmin;
% B= xmax;
% C= -M;
% D= +M;
% else
%
% end
hold on;
grid minor;
plot(x1,y1,'ok');
plot(x2,y2,'ok');
fimplicit(l1,'k');
fimplicit(l2,'k--');
fimplicit(l3,'k:');
yline(0,'k');
xline(0,'k--');
xline(xmin,'g--');
xline(xmax,'g--');
yline(ymin,'g--');
yline(ymax,'g--');
fimplicit(f);
fimplicit(F, [xmin xmax -M M]);
%fimplicit(F);
axis equal;
xlim([-M M]);
ylim([-M M]);
% legend show;
% legend location best;
hold off;
Answers (0)
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!