Upper limit a symbolic vector

8 ビュー (過去 30 日間)
Jacopo Stefano Ragazzini
Jacopo Stefano Ragazzini 2021 年 6 月 28 日
回答済み: Walter Roberson 2021 年 6 月 29 日
Hi,
I need to resolve the following problem:
I have a vector of input numbers (in) and I have to multiply it for a variable (a). My output (out) must be that vector that has an upper limit of 100 (clearly the output depends on the variable). Then I need to sum the vector "out" and divide it for "a" and plot the result in function of "a". I tried this way:
syms a
A=in*a;
out=min(A,100);
fun=sum(out)/a;
fplot(fun)
As far as I understand though I cannot run the "min" command because that instruction doesn't work on a symbolic vector. Anyway the error is:
Error using symengine
Input arguments must be convertible to floating-point numbers.
Error in sym/privBinaryOp (line 1030)
Csym = mupadmex(op,args{1}.s, args{2}.s, varargin{:});
Error in sym/min (line 78)
C = privBinaryOp(X, Y, 'symobj::zipWithImplicitExpansion', 'symobj::minComplex');
In case it's important for the help, the aim of the excersise is writing a mathematical function (fun) based on the variable "a"; the actual value of "a" will be determined only at the end minimizing the function "fun".
Thank you in advance

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 6 月 29 日
in = randi([-9 9], 1, 50)
in = 1×50
2 5 -5 4 5 -8 5 0 9 3 0 4 6 -7 -5 5 -3 9 5 -8 -6 8 2 -2 -1 6 -9 7 -3 0
Min = @(P,Q) arrayfun(@(p,q) piecewise(p <= q, p, q), P, Q);
syms a
A = in*a
A = 
out = Min(A,repmat(100,size(A)));
fun = sum(out)/a
fun = 
fplot(fun, [-100 100])

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by