0
|
3667 Views
|
3 Replies
|
4 Total Likes
View groups...
Share
GROUPS:

# How to run a line function through points

Posted 11 years ago
 I have 2 sets of input, one that displays 3 points and the other that displays a line function.  Seperately they both work fine but I cannot figure out how to combine them so that the line function appears on the same graph as the points.Here is the line function:Clear[f,x];a = -0.3;b = 2;f[x_] = a x + b;Plot[f[x],{x,0,5}, PlotStyle->{{Red,Thickness[0.015]}},  AxesLabel->{"x","f[x]"}]And here are the points: globb1 = Graphics[{Green,PointSize[0.15], Point[{1,4}]}];  globb2 = Graphics[{Green,PointSize[0.18], Point[{3,1.4}]}];  globb3 = Graphics[{Green,PointSize[0.17], Point[{4.2, 2.3}]}];   moregreenblobs =Show[globb1,globb2,globb3,PlotRange->{{0,5},{0,5}},      Axes->True, AxesOrigin->{0,0}, AxesLabel->{"x","y"}]
3 Replies
Sort By:
Posted 11 years ago
 Try this:a = -0.3;b=2;f[x_]:=a x + b;line=Plot[f[x],{x,0,5}, PlotStyle->{{Red,Thickness[0.015]}},  AxesLabel->{"x","f[x]"}];points=Graphics[{Green,PointSize[0.15], Point[{1,4}],PointSize[0.18], Point[{3,1.4}],PointSize[0.17], Point[{4.2, 2.3}]}];Show[line,points,PlotRange->{{0,5},{0,5}},      Axes->True, AxesOrigin->{0,0}, AxesLabel->{"x","y"}]this is what you get:
Posted 11 years ago
 Welcome to Wolfram Community, Bill! Please note how your code was formatted in special code-blocks. This makes it easy to read it and copy it. Use Spikey button in the editor - see image below. If you could also upgrade your profile information - it'd be great!
Posted 11 years ago
 Save the line plot,plt = Plot[f[x], .... and combine it with the dots, Show[moregreenblobs, plt]