Collinearity code not working?
    7 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
Question: mylinecheck(a,b,c,d,e,f) which takes six inputs: [30 pts] a,b,c,d,e,f: Real numbers. You may assume that a,c,e are all nonequal. Does: Checks if the three points (a, b), (c, d) and (e, f) all lie on the same line. How you do this is up to you but I suggest trying to find a really quick way. Quick ways exist! You’ll almost certainly need an if statement. Returns: 1 if they do and 0 if they don’t
Code:
if true
  % code
end
function mylinecheck(a,b,c,d,e,f)
p1 (a,b);
p2 (c,d);
p3 (e,f);
end
function tf = collinear2(p1,p2,p3)
m = slope(p1,p2);
b = intercept(p1,p2);
if ~isfinite(m)
if (p3(1)==p1(1))
tf = true;
else
tf = false;
end
else
tf = (m*p3(1)+b) == p3(2);
end
end
function m = slope(p1,p2)
m = (p2(2)-p1(2))/(p2(1)-p1(1));
end
function b = intercept(p1,p2)
m = slope(p1,p2);
b = -p1(2)+m*p1(1);
end
Test file:
format long;
a=mylinecheck(0,0,2,2,5,5)
Error: Error using mylinecheck Too many output arguments.
Error in Test (line 2) a=mylinecheck(0,0,2,2,5,5)
2 Commenti
  Star Strider
      
      
 il 10 Feb 2015
				It would definitely help if you used the [ {} Code ] button to format your code. It makes it easier to read, and if it’s easier to read, it’s more likely your Question will get an Answer.
Risposta accettata
  Star Strider
      
      
 il 10 Feb 2015
        See if changing the first line of your function to:
function g = mylinecheck(a,b,c,d,e,f)
and then assign ‘g’ (or whatever variable you want it to return) somewhere in your code as well. (The output argument and the variable you want the function to return must have the same name.) It is not obvious what you want your function to return, but it should also not be the same name as one of your input arguments (for example, (a,b,c,d,e,f)). That causes confusion at the very least, and could throw an error.
15 Commenti
  David Rogers
 il 20 Feb 2015
				could you post your corrected code so i can see what changes you made to get it to work properly?
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Logical in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


