Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'How to plot the function with 'if' or 'which'?' topicStudent Support Forum > General > Archives > "How to plot the function with 'if' or 'which'?"

Next Comment >Help | Reply To Topic
Author Comment/Response
Isaac
08/22/12 03:09am


I want to contourplot some function with different function depends on some conditions.

Such as

f(x) = up (when cond1>0)
down1 (when cond1>0, cond2>0)
down2 (when cond1>0, cond2<=0)



So my code is as follows

up[{\[Alpha]_, \[Beta]_, x_, y_, T_}] :=
Sqrt[(\[Alpha] - x)^2 + (\[Beta] - y)^2] +
Sqrt[(1 - \[Alpha])^2 + \[Beta]^2]

down[{\[Alpha]_, \[Beta]_, x_, y_, T_}] :=
If[T < (\[Alpha] - x)*Sqrt[1 + (y/(1 - x))^2], Sqrt[(1 - x)^2 + y^2],
Sqrt[(1 - \[Alpha])^2 + (T - (\[Alpha] - x)*
Sqrt[1 + (y/(1 - x))^2] + y/(1 - x)*(1 - \[Alpha]))^2]]

func[{\[Alpha]_, \[Beta]_, x_, y_, T_}] := Which[
condfunc[{\[Alpha], \[Beta], x, y, T}] <
0 && \[Alpha]*y - \[Beta]*x < 0,
up[\[Alpha], \[Beta], x, y, T],
condfunc[{\[Alpha], \[Beta], x, y, T}] >=
0 ,
down[\[Alpha], \[Beta], x, y, T]]


than

\[Alpha] = 0.95;
\[Beta] = 2;
T = 2.6;

ContourPlot[
func[{\[Alpha], \[Beta], x, y, T}], {x, 0, \[Alpha]}, {y,
0, \[Beta]}, AxesLabel -> {x, y}]



But Nothing is plotted. How should I?

URL: ,

Subject (listing for 'How to plot the function with 'if' or 'which'?')
Author Date Posted
How to plot the function with 'if' or 'which'? Isaac 08/22/12 03:09am
Re: How to plot the function with 'if' or 'whic... Bill Simpson 08/22/12 12:21pm
Next Comment >Help | Reply To Topic