How to calculate the crossing point and plotting the lines
3 次查看(过去 30 天)
显示 更早的评论
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
could you please help me to understand 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('your equation can be solved');
disp('to solve your equation');
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')
回答(1 个)
Jyotsna Talluri
2020-2-26
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');
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!