Solving an eq. using a large table by vpasolve is to slow
Show older comments
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 Comments
Torsten
on 26 Feb 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.
guy tau
on 26 Feb 2023
Moved: Walter Roberson
on 1 Mar 2023
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!