Mathematica中具有条件的多元函数 [英] Multivariate Functions with Conditions in Mathematica

查看:394
本文介绍了Mathematica中具有条件的多元函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图定义一个二元函数,它取决于条件是否满足取值。我让它们适用于单变量情况,但我坚持使用双变量情况:

  g [x_,y_]:= 10 /; x < 10 
g [x_,y_]:= 20 /; (x> = 10& y< 5)
g [x_,y_]:= -5 / (x> = 10& y> = 5);

这个函数永远不会给出-5的值。



g [12,10] = 20?

解决方案

这适用于我:

 清除[g] 
g [x_,y_] /; x < 10:= 10
g [x_,y_] /; x> = 10 [和] y< 5:= 20
g [x_,y_] /; x> = 10 \ [and] y> = 5:= -5

/ p>

 在[73]中:= g [12,10] 

输出[73] = -5

为什么这个版本可以正常工作,而您的版本不是我不确定。也许别人会来,告诉我们

I'm trying to define a bivariate function that takes values depending on whether a condition is met. I make them work for univariate case but I'm stuck with the bivariate case:

g[x_, y_] := 10 /; x < 10
g[x_, y_] := 20 /; (x >= 10 && y < 5)
g[x_, y_] := -5 /; (x >= 10 && y >= 5);

This function never gives me the value of -5.

g[12,10] = 20?

解决方案

This works for me:

Clear[g]
g[x_, y_] /; x < 10 := 10
g[x_, y_] /; x >= 10 \[And] y < 5 := 20
g[x_, y_] /; x >= 10 \[And] y >= 5 := -5

then

In[73]:= g[12, 10]

Out[73]= -5

Why this version works and your version doesn't I'm not sure. Perhaps someone else will come along and tell us

这篇关于Mathematica中具有条件的多元函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆