I have a equtions likes
y=f(7,2,0)+f(-1,2,0)+f(0,0,-1)+f(1,1,0)+f(0,-1,0)
if any inside the function is -ve , the function is zero
for example
f(-1,2,0)= 0 because there is a negative terms.
final answer is y =f(7,2,0)+f(1,1,0) because other function f have -ve terms.
Could you help me.

 채택된 답변

Walter Roberson
Walter Roberson 2020년 12월 30일
편집: Walter Roberson 2020년 12월 30일

0 개 추천

You can use mapSymType to process this
mapSymType(y, 'f', @(X)piecewise(any(cellfun(@(N) isAlways(N<0, 'unknown', false),children(X)) ), 0, X)
...something like that
mapSymType can be a bit of a nuisance. The object passed to the anonymous function would be the function call like f(-1,2,0) and you have to use children() to get at the arguments, which gives you a cell array so you have to cellfun...

댓글 수: 2

pradeep kunwar
pradeep kunwar 2021년 1월 4일
Could you, please explan about ''@(X)piecewise(any(cellfun(@(N) isAlways(N<0, 'unknown', false)"
What are X and cellfun(@(N)) ?
@(X) followed by an expression in X indicates an anonymous function. MATLAB takes the part after the @(X) and builds code for it, replacing the name X with a reference to the first parameter passed to the function.
Likewise the @(N) introduces a second anonymous function used within the first one.
The effect is like
mapSymType(y, 'f', @anonymous0)
function result0 = anonymous0(X)
result0 = piecewise(expression1(X), 0, X);
end
function result1 = expression1(X)
result1 = any( cellfun(@anonymous2, children(X)) )
end
function result2 = anonymous2(N)
result2 = isAlways(N<0, 'unknown', false)
end
So, look for symbolic function calls to f() . If you find one, replace it with a piecewise() construct that returns 0 if a condition is true and returns the original expression otherwise. The condition to be tested is to take all of the arguments to the function (children of a symbolic function call is the list of parameters passed to the function), and for each one, if you can prove that it is always negative, then the condition is true.
So take a parameter to a call to f, and if you can prove the parameter is always negative, return true, and if true was returned for any parameter, replace the entire call with 0.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

태그

질문:

2020년 12월 30일

댓글:

2021년 3월 10일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by