Hello,
I would like to solve a system of equations with parameters. An example (with trivial math) is attached. The system and the variables I would like to solve it for are dependent on a user input. In my example that is the varialbe "length" which can take an arbitrary positive natural number.
I can solve it by explicitly listing the variables "a(1)", etc. in the solve function call. Since the varialbe vector "a" is userdependent I cant use that in general though.
The second function call to solve results in warnings and wrong answers, because solve assumes that the second input "a" is an equation array and not the variables to be solved for.
Any suggestions to solve the system for, say, a random (positive and natural number) "length"?
Thanks a lot in advance!
length = 3;a = sym('a', [length, 1]);equations = sym('something', [length, 1]);syms pfor runIdx = 1:length equations(runIdx) = a(runIdx) - p == 0;endanswers_correct_but_static = solve(equations, a(1), a(2), a(3))answers_incorrect_dynamic = solve(equations, a)
Best Answer