フィルターのクリア

How to test if equation in .p file is linear.

3 ビュー (過去 30 日間)
V_Izepatchy
V_Izepatchy 2023 年 9 月 26 日
回答済み: Walter Roberson 2023 年 9 月 26 日
I have a .p file that has an equation in it that I can’t ever know. How would you call it in a script and test for linearity (additivity, scalability).
  1 件のコメント
V_Izepatchy
V_Izepatchy 2023 年 9 月 26 日
If it helps, I’m using a unit step function

サインインしてコメントする。

回答 (2 件)

Walter Roberson
Walter Roberson 2023 年 9 月 26 日
In some cases you might get lucky, in that if you pass purely symbolic variables to the function, you might get back a formula. That would fail if the function has conditional tests based on the inputs.
The existence of conditional tests based on the input would tend to hint that likely the function is not linear. It is, however, not proof, as the conditional tests might effectively be irrelevant. For example,
if x >= 0
y = x.^2;
else
y = (-x).^2;
end
In this example although there is a conditional test, algebraically it turns out not to matter for the outcome -- so the presence of conditional elements is not proof that the function is not linear.

Matt J
Matt J 2023 年 9 月 26 日
編集済み: Matt J 2023 年 9 月 26 日
Well, there's no test that will verify linearity globally (for all inputs), but you can select random inputs and test the applicable properties, e.g.,
x=rand; y=rand;
norm( func(x)+func(y)-func(x+y) ) %should be close to zero

カテゴリ

Help Center および File ExchangeHypothesis Tests についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by