No advanced topic here, just some simple/silly/useless problems that slip into my mind during lunch break. Free use the contents in any way you like.
Thank you! I couldn't find another way to contact you, and was hoping you'd eventually read the old comments...
A slightly simplified version:Clear[a]Clear[b]Clear[c]Clear[x]Clear[y]Clear[sum](*Expressing three parameters a,b, and c in terms of the Cartesian \coordinates x and y with the constraint that a+b+c=sum*)sum := 1(*a, b, and c are defined so that 100% a corresponds to the lower \left corner, 100% b to the lower right corner, and 100% c to the top \corner.*)b[x_, y_] := (x - y*Tan[Pi/6])*Cos[Pi/6]a[x_, y_] := ((sum - x) - y*Tan[Pi/6])*Cos[Pi/6]c[x_, y_] := y(*Defining a function f (a,b,c)*)f[x_, y_] := Cos[a[x, y]] + Sin[b[x, y]] + Sin[c[x, y]](*Drawing the contour plot*)cp = ContourPlot[f[x, y], {x, 0, sum}, {y, 0, sum}](*Drawing the Triangle which bounds all allowed values of (a,b,c)*)tr = Graphics[{Thick, Line[{{0, 0}, {sum, 0}, {0.5*sum, Sqrt[3]*sum/2}, {0, 0}}]}, ImageSize -> 300](*Putting it all together*)Show[cp, tr]
First of all, this is fantastic. I use triangle plots all the time and and a new user of Mathematica, I was very happy to find this. And just a quick question, how do you think this would go plotting lines?
This is awesome!
Post a Comment
4 comments:
Thank you! I couldn't find another way to contact you, and was hoping you'd eventually read the old comments...
A slightly simplified version:
Clear[a]
Clear[b]
Clear[c]
Clear[x]
Clear[y]
Clear[sum]
(*Expressing three parameters a,b, and c in terms of the Cartesian \
coordinates x and y with the constraint that a+b+c=sum*)
sum := 1
(*a, b, and c are defined so that 100% a corresponds to the lower \
left corner, 100% b to the lower right corner, and 100% c to the top \
corner.*)
b[x_, y_] := (x - y*Tan[Pi/6])*Cos[Pi/6]
a[x_, y_] := ((sum - x) - y*Tan[Pi/6])*Cos[Pi/6]
c[x_, y_] := y
(*Defining a function f (a,b,c)*)
f[x_, y_] := Cos[a[x, y]] + Sin[b[x, y]] + Sin[c[x, y]]
(*Drawing the contour plot*)
cp = ContourPlot[f[x, y], {x, 0, sum}, {y, 0, sum}]
(*Drawing the Triangle which bounds all allowed values of (a,b,c)*)
tr = Graphics[{Thick,
Line[{{0, 0}, {sum, 0}, {0.5*sum, Sqrt[3]*sum/2}, {0, 0}}]},
ImageSize -> 300]
(*Putting it all together*)
Show[cp, tr]
First of all, this is fantastic. I use triangle plots all the time and and a new user of Mathematica, I was very happy to find this. And just a quick question, how do you think this would go plotting lines?
This is awesome!
Post a Comment