# How to calculate the crossing point and plotting the lines

18 views (last 30 days)
Razan AlJuraysi on 19 Feb 2020
Answered: Jyotsna Talluri on 26 Feb 2020
Hello
I am new to matlab AND I want to calculate the crossing points and plot lines
this is my code but I dont know whats wrong with it
thank you
disp('welcome'); % description from line 1 to 7
disp('this is a crossing point calculator');
disp('from the equations');
disp('ax+by=c and dx+ey=f');
disp('please,Enter values for a,b,c,d,e and f');
a =('please, input the value for a:'); % asking the user to input values
b =('please, input the value for b:');
c =('please, input the value for c:');
d =('please, input the value for d:');
e =('please, input the value for e:');
f =('please, input the value for f:');
xmin= input('please, input the value for x min=');
xmax= input('please, input the value for x max=');
x= xmin:xmax;
y1=(c/b)-(a/b).*x;
y2=(f/e)-(d/e).*x;
c =[a*xmin+b*y1];
f =[d*xmax+e*y2];
m1=-(a/b);
m2=-(d/e);
c1=c/b;
c2=f/e;
if (m1==m2)&&(c1==c2)
disp('the same line')
elseif m1==m2
disp('the lines are parallel no crossing point exist')
else
x=((b*f)-(c*e))/((-a*e)+(b*d));
output ('crossing point exist')
xi=((f/e)-(c/b))/((d/e)-(a/b));
yi=(-a/b)*xi+(c/b);
plot(xi,yi,'d','c')
end
hold on;
plot(x,y1)
plot(x,y2)
title('Coordinate grid')
xlable('x - axis')
ylabel('y - axis')
KSSV on 19 Feb 2020
What you want to do? What is problem with the code?

Jyotsna Talluri on 26 Feb 2020
When you are asking the user for inputs , use input function to assign a value to variable like
>> a =input('please, input the value for a:');
In your code, you should not be assigning c and f as below due to which intercepts c1 and c2 takes array of values.
c =[a*xmin+b*y1];
f =[d*xmax+e*y2];
With the plot function, you have to specify the Marker and Color in the third argument itself
plot(xi,yi,'db');