Solver Finding the slope
Algebra
->
Algebra
->
Linear-equations
-> Solver Finding the slope
Log On
Ad:
Algebra Solved!™
: algebra software solves algebra homework problems with step-by-step help!
Ad:
Algebrator™
solves your algebra problems and provides step-by-step explanations!
Algebra: Linear Equations, Graphs, Slope
Solvers
Lessons
Problems, free tutors
Quiz
In Depth
Source code of 'Finding the slope'
This Solver (Finding the slope)
was created by by
jim_thompson5910(13794)
:
View Source
,
Show
,
Put on YOUR site
About jim_thompson5910
:
==section input Input two points x1=*[input xcoord1=2] y1=*[input ycoord1=3] x2=*[input xcoord2=4] y2=*[input ycoord2=5] to find the slope. ==section solution perl sub reduce{ my @arr1, $flag; #$arr1[0]=$_[0]; #$arr1[1]="/"; #$arr1[2]=$_[1]; @arr1=@_; $arr1[2]=$arr1[1]; $arr1[1]="/"; $flag=$_[2]; if($arr1[0]==0) {return $arr1[0];} if($arr1[2]!=0) { $store=$arr1[0]/$arr1[2]; if($store>0) { $arr1[0]=abs($arr1[0]); $arr1[2]=abs($arr1[2]); } if(($store<0)&&($arr1[2]<0)) { $arr1[0]=0-$arr1[0]; $arr1[2]=abs($arr1[2]); } if($arr1[0]%$arr1[2]==0) { if($flag==1) {$arr1[0]=$arr1[0]/$arr1[2]; return $arr1[0];} if($flag==2) {$arr1[0]=$arr1[0]/$arr1[2]; $arr1[2]=1; return ($arr1[0],"/",$arr1[2]);} # if($flag==0) # {return $quotient;} } } for (my $i=abs($arr1[0]*$arr1[2]); $i>1; $i--) { if (($arr1[0]%$i==0)&&($arr1[2]%$i==0)) { $arr1[0]/=$i; $arr1[2]/=$i; my $j=$i; } } return ($arr1[0],"/",$arr1[2]); } if($xcoord1==$xcoord2) { my $rise=$ycoord2-$ycoord1; my $run=$xcoord2-$xcoord1; print "To find the slope going from ($xcoord1,$ycoord1) to ($xcoord2,$ycoord2) we are going to calculate the change in y over the change in x, or the rise over the run. The change is the difference between the two coordinates. So if the y-coordinate of a point goes from $ycoord1 to $ycoord2, the change in these numbers is $rise (since {{{$ycoord2-$ycoord1=$rise}}}). If the x-coordinate changes from $xcoord1 to $xcoord2, then the change is $run (since {{{$xcoord2-$xcoord1=$run}}}). So to calculate the slope we use this formula: \n"; print "\n Slope: {{{m=(change_in_y)/(change_in_x)=rise/run}}} where m is the slope"; print " So now we let {{{y[2]=$ycoord2}}},{{{y[1]=$ycoord1}}},{{{x[2]=$xcoord2}}},{{{x[1]=$xcoord1}}}Now plug these numbers into the slope formula: "; print "{{{m=(y[2]-y[1])/(x[2]-x[1])=($ycoord2-($ycoord1))/($xcoord2-($xcoord1)) = $rise/$run}}}"; print "Since the two points have the same x-coordinate, we have a denominator of zero. Remember we cannot divide by zero. In other words, this is not possible: {{{x/0}}} (we cannot divide any number by 0) This means the slope is undefined, and because we don't have any change in x, we have a vertical line at x=$xcoord1"; return undef; } my $rise=$ycoord2-$ycoord1; my $run=$xcoord2-$xcoord1; my $slope=$rise/$run; my $mod=$rise%$run; print "To find the slope going from ($xcoord1,$ycoord1) to ($xcoord2,$ycoord2) we are going to calculate the change in y over the change in x, or the rise over the run. The change is the difference between the two coordinates. So if the y-coordinate of a point goes from $ycoord1 to $ycoord2, the change in these numbers is $rise (since {{{$ycoord2-$ycoord1=$rise}}}). If the x-coordinate changes from $xcoord1 to $xcoord2, then the change is $run (since {{{$xcoord2-$xcoord1=$run}}}). So to calculate the slope we use this formula: \n"; print "\n Slope: {{{m=(change_in_y)/(change_in_x)=rise/run}}} where m is the slope"; print " So now we let {{{y[2]=$ycoord2}}},{{{y[1]=$ycoord1}}},{{{x[2]=$xcoord2}}},{{{x[1]=$xcoord1}}}Now plug these numbers into the slope formula: "; print "{{{m=(y[2]-y[1])/(x[2]-x[1])=($ycoord2-($ycoord1))/($xcoord2-($xcoord1)) = $rise/$run}}}"; print "\n"; @temp=reduce($rise,$run,2); $final_fraction="@temp"; $final_fraction=~s/\s//g; $final_fraction=~s/\/1$//; print " So after simplification the slope is {{{m=$final_fraction}}}"; ==section output angle1, xcoord1, ycoord1,xcoord2,ycoord2 ==section check angle=40 angle1=50