Rearrange Variables in an equation that are changing everytime
1 次查看(过去 30 天)
显示 更早的评论
I want to get one variable in terms of the other variables in the equation. For example
syms a b
eqn = ('a + 2*b = 1')
v_a = solve(eqn, a)
v_b = solve(eqn, b)
This works fine
My issue is that the variables and the number of variables can change in each iteration.
My variables alpha1, alpha2 and alpha3 are defined by sym and not syms. I need to do this as the no of alpha's is determined by the input data size. This case 3.
data = [-1 0 1;-1 +1 -1]';
alpha = sym('alpha',[1 3]); %output "[ alpha1, alpha2, alpha3]"
st = 'alpha*data(:,2)=0' %output should be "alpha2 - alpha1 - alpha3 = 0" but I dont get this. instead, its something else
v_2 = solve(st,alpha(1)) %doesnt work because the previous line is wrong
Thanks and appreciate any help
0 个评论
采纳的回答
Star Strider
2012-7-20
This:
data = [-1 0 1;-1 +1 -1]';
alpha = sym('alpha',[1 3]);
advct = alpha * data(:,2)
v_2 = solve(advct == 0, alpha(1))
gives me these:
advct =
alpha2 - alpha1 - alpha3
v_2 =
alpha2 - alpha3
Is that the result you were hoping for?
6 个评论
Star Strider
2012-7-21
My pleasure! We are here to help.
And thank you again for accepting my answer!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!