0-by-1 error when solving for 2 sets of simultaneous equation

2 次查看(过去 30 天)
I'm trying to solve 2 sets of simultaneous equation in one program, where the answers of eqn1 and eqn2 get put into eqn3 and eqn4.
eqn1 and eqn2 solve correctly, but eqn3 and eqn 4 have error of "Empty Sym: 0-by-1".
The error happens in the following code:
syms l3 l4
eqn3= mr2 * l2 * cosd(t2) + mr3 * l3 * cosd(t3) + mr4 * l4 * cosd(t4anti) == 0;
eqn4= mr2 * l2 * sind (t2)+ mr3 * l3 * sind(t3) + mr4 * l4 * sind(t4anti) ==0;
sol = solve ([eqn3, eqn4], [l3, l4])
Where t3 and t4anti are the variables solved previously in eqn1 and eqn2, and l3 and l4 need to be calculated.
I'm not sure if you can set it up to solve two unknowns, then solve two further unknowns, and I saw advice of using subs() but I'm not sure how I'd do this with it needing to use angles.
Any advice is appreciated, thank you!

回答(1 个)

Jaynik
Jaynik 2023-12-18
Hi Sam,
I understand that you are trying to solve equations using solution from previously solved equations. I am assuming that all variables except “t3”, “t4anti”, “l3” and “l4” are defined and used correctly.
Before solving for “l3” and “l4”, you need to check that “eqn1” and “eqn2” are independent and have unique solutions for “t3” and “t4anti”. If they do not have unique solutions or are dependent on each other, you will need to address that issue before solving for “l3” and “l4”.
If the result for “t3” and “t4anti” is correct, you can directly use them in “eqn3” and “eqn4” as symbol variables. Their value should automatically get substituted. Alternatively, you can use “subs” function to replace old occurrences of a symbolic variable with the new one.
Following is a reference code for usage of “subs” function in your code:
eqn3_sub = subs(eqn3, t3, t3_solution);
final_eqn3 = subs(eqn3_sub, t4anti, t4anti_solution);
eqn4_sub = subs(eqn4, t3, t3_solution);
final_eqn4 = subs(eqn4_sub, t4anti, t4anti_solution);
sol = solve([final_eqn3, final_eqn4], [l3, l4]);
You can refer to the following documentation to read more about the “subs” function:
Hope this helps!
Regards,
Jaynik

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by