Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your function to return an output with the same size and shape as the input arguments

Why am I getting the warning?
EDIT: removed VER information.
%% Hill equation
% Rate = Vmax * S^n / (K^n + S^n)
hill = @(S,Vmax,K,n) Vmax*S^n / (K^n + S^n);
%Check Michaelis Menton Function using S, Vmax=1, Km=0.1, and n=1)
hill_1 = @(S) hill(S, 1, 0.1, 1);
figure(1)
fplot(hill_1, [0,3])
Warning: Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your function to return an output with the same size and shape as the input arguments.

 採用された回答

Hi @Elle,
While the formula is correct, the MATLAB code provided works well for scalar values but requires element-wise operations when working with matrices. By default, MATLAB assumes matrix operations on the variables. To address the warning encountered, the code should be modified as follows:
% Note element-wise operations
hill = @(S,Vmax,K,n) Vmax .* S.^n ./ (K.^n + S.^n);
% Check Michaelis-Menten Function using S, Vmax=1, Km=0.1, and n=1
hill_1 = @(S) hill(S, 1, 0.1, 1);
% Plot the function
figure(1)
fplot(hill_1, [0, 3])
Further information can be found in the following documentation::
Hope this helps.

3 件のコメント

Elle
Elle 2024 年 9 月 25 日
Thank you! This was very helpful.
Hi @Elle,
I'm glad that this answer helped you! Please consider accepting the answer next time so that others in the community can benefit from it as well.
Elle
Elle 2024 年 10 月 1 日

Done! Thanks

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

製品

リリース

R2024b

質問済み:

2024 年 9 月 25 日

コメント済み:

2024 年 10 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by