I need to Plot
two functions one is on x-axis and second on y-axis, both function have common variable $x$. The two functions are
myfunction1[{al_, be_, ga_}] := (al*be)/2 Cos[x]
(Sec[x/2])^2 (Tan[x/2])^-(be + 1) (1 + ga (Tan[x/2])^-be)^(-(al/ga) - 1)
myfunction2[{al_, be_, ga_}] := (al*be)/2 Sin[x] (Sec[x/2])^2 (Tan[x/2])^-(be + 1) (1 +
ga (Tan[x/2])^-be)^(-(al/ga) - 1)
where $0Mathematica
to plot this?
Answer
The main difficulty of most beginners with Mathematica is that they start with a somewhat complicated problem (displaying two functions that have three parameters in one graphic) and then trying to do it all at once. First you have to understand how various Plot types work, such as Plot and ParametricPlot, and probably how to use graphics Options to control the look of the graphic. Then there is the question of whether the graphs of each of the functions can be reasonably combined in a single plot. And why do you say you want to plot one function on the x axis and the other on the y axis? That seems quixotic because maybe the range of the first function is discordant with the domain of the second function, and how would that make a good way to compare the two functions? Perhaps that was an error and you meant plotting both against the x axis with different scales on the left and right y axes? Plotting data, or functions, depends an awful lot on what the data or functions actually look like. One can't just go ahead with a generic approach without looking at the functions because all kinds of problems can arise depending on the parameters.
So let's just explore some first. Here is a somewhat different method for defining your first function.
myfunction1[{al_, be_, ga_}][
x_] := (al*be)/2 Cos[
x] (Sec[x/2])^2 (Tan[x/2])^-(be + 1) (1 +
ga (Tan[x/2])^-be)^(-(al/ga) - 1)
I've added an extra set of square brackets to contain the parameters and the final set of [] brackets contains the variable. The first set is known as SubValues in Mathematica. We wouldn't have to put the parameters in a List, but I went along with that. This type of definition has certain advantages: besides separating parameters from variables, it makes it easy to calculate derivatives with respect to the variable. For example:
myfunction1[{a, 1, 1}]'[x]
giving
-(1/2) a Cos[x] Cot[x/2] (1 + Cot[x/2])^(-1 - a) Csc[x/2]^2 -
1/4 (-1 - a) a Cos[x] (1 + Cot[x/2])^(-2 - a) Csc[x/2]^4 -
1/2 a (1 + Cot[x/2])^(-1 - a) Csc[x/2]^2 Sin[x]
Now let's plot with the parameters {1,1,1}
.
Plot[myfunction1[{1, 1, 1}][x], {x, 0, \[Pi]},
Frame -> True,
ImageSize -> 250]
Notice that I used a Frame instead of the default Axes plot. This was done with the Frame option. This is almost always better. If you do a lot of graphics you will want to get to know the options. Next you might want to explore the function in the parameter space. Here is a little custom dynamic module for doing it. (Most users use Manipulate but it can sometimes tie you in knots and it's often easier to construct a custom dynamic.)
DynamicModule[{a = 1, b = 1, c = 1},
Column[{
Row[{"a", Spacer[10],
Slider[Dynamic[a], {0, 5}, Appearance -> "Labeled"]}],
Row[{"b", Spacer[10],
Slider[Dynamic[b], {0, 5}, Appearance -> "Labeled"]}],
Row[{"c", Spacer[10],
Slider[Dynamic[c], {0, 5}, Appearance -> "Labeled"]}],
Dynamic@
Plot[myfunction1[{a, b, c}][x], {x, 0, \[Pi]},
Frame -> True,
ImageSize -> 250]
}]
]
I won't display it here, but it you start exploring with it you will find a serious problem. The scale on the vertical axis keeps changing! This is because without further guidance Mathematica determines what it thinks is a reasonable plot range, and it does this each time you move one of the sliders. Any dynamic plot requires a fixed background (you would be astonished at how often beginners make that mistake.) So take the control away from Mathematica and specify a specific fixed plot range. The following does that.
DynamicModule[{a = 1, b = 1, c = 1},
Column[{
Row[{"a", Spacer[10],
Slider[Dynamic[a], {0, 5}, Appearance -> "Labeled"]}],
Row[{"b", Spacer[10],
Slider[Dynamic[b], {0, 5}, Appearance -> "Labeled"]}],
Row[{"c", Spacer[10],
Slider[Dynamic[c], {0, 5}, Appearance -> "Labeled"]}],
Dynamic@
Plot[myfunction1[{a, b, c}][x], {x, 0, \[Pi]},
Frame -> True,
PlotRange -> {-1, 2},
ImageSize -> 250]
}]
]
Now define your second function and explore it.
myfunction2[{al_, be_, ga_}][
x_] := (al*be)/2 Sin[
x] (Sec[x/2])^2 (Tan[x/2])^-(be + 1) (1 +
ga (Tan[x/2])^-be)^(-(al/ga) - 1)
I'll leave the exploration to you. Just follow the example above.
Unless you have some really good reason, I would plot both functions on the x axis. As an example:
Plot[{myfunction1[{1, 1, 1}][x], myfunction2[{1, 1, 1}][x]}, {x,
0, \[Pi]},
Frame -> True,
ImageSize -> 250]
Now you could use that plot in a DynamicModule. Again you will have to specify a PlotRange as before. You might consider scaling one or the other of the two functions and you might include this scaling information in the FrameLabel. There are other techniques, but I'm getting tired and I hope that helps enough. Remember that the method of presentation depends critically on what the data, functions or phenomenon actually is!
If you really want the functions on the x and y axes then you have to say what the purpose is so that it might be done in an intelligent manner.
Comments
Post a Comment