Recommended pattern for applying a polynomial of sdpvar variables to a large matrix #1249
-
Hi @johanlofberg, I need to apply a polynomial of sdpvar variables to a very large matrix. Unfortunately, I didn't come up with a solution (or a prompt to ChatGPT) to optimize this (probably bad) pattern: sdpvar x y a b c d e
f = a*x^2 + b*x + c*y;
g = d*x + e*y;
A = randn(2,5000);
B = double2sdpvar(zeros(2, 1000));
for n = 1:5000
B(1, n) = replace(f, [x y], [A(1,n) A(2,n)]);
B(2, n) = replace(g, [x y], [A(1,n) A(2,n)]);
end Do you have any suggestion to make it run faster? |
Beta Was this translation helpful? Give feedback.
Answered by
johanlofberg
Mar 23, 2023
Replies: 1 comment 1 reply
-
Why don't you simply create the expression directly
replace will be hard to get fast |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
htadashi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why don't you simply create the expression directly
a*A(1,:).^2 + b*A(1,:) + c*A(2,:)
replace will be hard to get fast