How can I perform a recursive input using the solve function?

6 次查看(过去 30 天)
I've created some code to simulate a crank-rocker mechanism and I'm wondering how to perform an operation where I take the crank rotating 360 degrees and spit out all of the theta values for each corresponding link of the mechanism.
For reference: r1 = ground, r2 = crank, r3 = attachment link, r4 = rocker
t1, t2, t3, t4 are all thetas for reach respective link
Here is the code:
r1=4.2; r2=1; r3=5; r4=2.032;
t1=0; t2=0:1:360;
syms t3 t4 positive
eqn1 = r2.*cosd(t2)+r3.*cosd(t3)==r1.*cosd(t1)+r4.*cosd(t4);
eqn2 = r2.*sind(t2)+r3.*sind(t3)==r1.*sind(t1)+r4.*sind(t4);
S = solve(eqn1, eqn2, 'IgnoreAnalyticConstraints', true)
When I run the code, it gives me 4 error messages:
Second argument must be a vector of symbolic variables.
checkVariables(vars)
[eqns, vars] = sym.getEqnsVars(argv{:});
Error in sym/solve (line 226)
[eqns,vars,options] = getEqns(varargin{:});
I'm just looking to find a way to scale t2 from 0 to 360 degrees such that t3 and t4 give positive values only. I know how to do this with a single number, but once t2 becomes an array, I don't know how to solve those issues.

采纳的回答

Walter Roberson
Walter Roberson 2020-12-14
t1=0; t2=0:1:360;
So t2 is a vector of length 361
eqn1 = r2.*cosd(t2)+r3.*cosd(t3)==r1.*cosd(t1)+r4.*cosd(t4);
With t2 being a vector of length 361, the left hand side of the == is a vector. The right hand side is a scalar, but expansion will be done so that you will get a vector of equations, one for each element of t2.
Likewise, eqn2 will be a vector of equations.
solve(eqn1, eqn2, 'IgnoreAnalyticConstraints', true)
with two vectors of length 361, would be trying to solve 722 simultaneous equations, in a total of two unknowns.
You are not going to be able to find a part of t3 and t4 values that manages to solve all 722 equations simultaneously .
You will need something like
arrayfun(@(E1, E2) solve(E1, E2, [t3, t4], 'IgnoreAnalyticConstraints', true), eqn1, eqn2, 'uniform', 0)
  1 个评论
Evan Anderson
Evan Anderson 2020-12-19
Thanks for this. I ended up being able to use a while loop pretty easily, I just had to rearrange some things. Any and all help was appreciated!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by