Solving an eq. using a large table by vpasolve is to slow
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I'm trying to use the solve function of MATLAB using a relatively large table of data (~30000 rows).
My eq. uses some of the variables from the table to predict and compare to a known sampled variable.
Yet, the running time for solving the eq. by using a loop yields such large running time.
I imagine that their some easier and faster way to solve this eq, and I hope I reached the right place.
First, I used the next code:
syms X
for i = 1:height(a)
Equation = ((a.var1(i) -c1*(X)^4)- (c2*a.var2(i)*(6.105.*exp((c3*X)./(x+c4)) -a.var3(i))) - (c5*(x-a.var4(i)))) = 0;
solution(i) = double(vpasolve(eqn(i),Tw));
end
where
c1,c2,c3,c4 and c5 are constants
and a.var1 to a.var 4 are the variables from the table
Later, I saw some further solutions online, that convert the code to:
ThemeCopy
syms a.var1 a.var2 a.var3 a.var4 i X
Equation = ((a.var1(i) -c1*(X)^4)- (c2*a.var2(i)*(6.105.*exp((c3*X)./(x+c4)) -a.var3(i))) - (c5*(x-a.var4(i)))) = 0;
tsym = solve(simplify(Equation), X);
tfun = matlabFunction(tsym, 'vars', {'a.var1', 'a.var2', 'a.var3', 'a.var4','i'});
for i = 1:height(a)
t(i) = tfun(a.var1,a.var2,a.var3,a.var4, i);
end
Unfortunately, I got the following error back
Error using sym/subsindex
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic variables, and function body must be sym expression.
Error in indexing (line 1075)
R_tilde = builtin('subsref',L_tilde,Idx);
Related documentation
I assume the problem is related to the index table, but i'm struggling to find the solution
If other solution pop's to your mind that will be great as well.
Tnx in advance.
2 commentaires
Torsten
le 26 Fév 2023
Please supply the equation(s) you are trying to solve and the variable(s) you are trying to solve for in a mathematical notation.
I cannot recover this information from your code.
Réponse acceptée
Torsten
le 26 Fév 2023
Déplacé(e) : Torsten
le 26 Fév 2023
syms A.var1 A.var2 A.var3 A.var4 X
Equation = ((A.var1 -c1*X^4)- (c2*A.var2*(6.105.*exp((c3*X)./(X+c4)) -A.var3)) - (c5*(X-A.var4))) == 0;
for i = 1:height(a)
X_num(i) = double(vpasolve(subs(Equation,[A.var1 A.var2 A.var3 A.var4],[a.var1(i) a.var2(i) a.var3(i) a.var4(i)]),X))
end
4 commentaires
Walter Roberson
le 26 Fév 2023
On thing that can help is to feed the previous result as the initial guess. vpasolve(expression, guess) in the single variable case. This assumes that the solution for this new case is probably "close" to the previous one. The performance difference can be a lot.
Walter Roberson
le 1 Mar 2023
syms A.var1 A.var2 A.var3 A.var4 X
You cannot 'syms' a dot-indexed variable. The closest you can get would be
A.var1 = sym('var1'); A.var2 = sym('var2'); A.var3 = sym('var3');
But I think you would be better off using
syms var [1 4]
syms X
X_num(i) = double(vpasolve(subs(Equation, var, [a.var1(i) a.var2(i) a.var3(i) a.var4(i)]),X))
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
