1
$\begingroup$

I've got some problems solving (numerically) this system of equations.

\begin{array}{l} 40 \cdot \cos (2t) + 105 \cdot \cos ({\theta _3}) - 75 \cdot \cos ({\theta _4}) - 91.924 \cdot \cos ({337.62}) = 0\\ 40 \cdot \sin(2t) + 105 \cdot \sin({\theta _3}) - 75 \cdot \sin({\theta _4}) - 91.924 \cdot \sin({337.62}) = 0 \end{array}

Now t is an array of numbers (variable?) ranging from 0 to 0.785 like this t = 0:0.01:0.785.

I was wondering if it is possible to find $\theta_3$ and $\theta_4$ for every t (like t=0 --> $\theta_3$=something, $\theta_4$=something...t=0.4-->$\theta_3$="something else", $\theta_4$="something else") put those values(solutions) in an array (vector)so that I can plot them.

I've tried to do it symbolically with solve but MATLAB couldn't find any (useful) solution. I tried to solve it numerically but I couldn't make it spit out more than two solutions at a time.

I've done it in Mathcad but I need to solve this with MATLAB (I'm new to MATLAB).

$\endgroup$
  • $\begingroup$ Is $\theta_1$ also an unknown? $\endgroup$ – GertVdE Apr 7 '14 at 18:14
  • $\begingroup$ No, theta1 is 337.62 (deg). Sorry I didn't point that out earlier. $\endgroup$ – John Dr.Cox Dorian Apr 7 '14 at 18:17
2
$\begingroup$

I would loop over t and solve the system using the fsolve command. For $t=0$, it shouldn't be too difficult with a reasonable initial guess. And then solve each problem using as initial value the solution of the previous value for $t$...

Define your function as

function [res] = problem(x,t)

t1 = 337.62/180.0*pi;
t3 = x(1);
t4 = x(2);

res = zeros(2,1);
res(1) = 40.0*cos(2*t)+105*cos(t3)-75*cos(t4)-91.924*cos(t1);
res(2) = 40.0*sin(2*t)+105*sin(t3)-75*sin(t4)-91.924*sin(t1);

return;

Define the values of the parameter:

t = [0:0.01:0.785] 

Make room for the solutions:

sols = zeros(2,length(t))

Solve for $t=0$ with an initial guess of $\theta_3 = \theta_4 = 1$ (arbitrary)

theta0 = [1,1];
sols(:,1) = fsolve(@(x) problem(x,t(1)),theta0)

And then loop over the remaining values for $t$ using the previous solution as initial guess:

for i=2:length(t),
  sols(:,i) = fsolve(@(x) problem(x,t(i)),sols(:,i-1))
end

and plot

plot(t,sols(1,:),t,sols(2,:))

Caveat: my Matlab is a bit rusty (my switch to Python/Numpy/Scipy is already a couple of years ago...)

$\endgroup$
  • $\begingroup$ Thank you for your answer Gert. Even though your method might work I don't think I'd be able to do it since I'm new to MATLAB and this sounds kinda complicated. $\endgroup$ – John Dr.Cox Dorian Apr 7 '14 at 18:22
  • $\begingroup$ Just another thing. Here sols(:,i) = fsolve(@(x) problem(x,t(i)),sols(:,i-1)) with @ you're passing a reference of the function problem(x,t) to fsolve right? And the previous solutions sols(:,i-1) is used as a guess for the next one right? $\endgroup$ – John Dr.Cox Dorian Apr 7 '14 at 19:08
  • $\begingroup$ Yes, that is correct. $\endgroup$ – GertVdE Apr 7 '14 at 19:22
  • $\begingroup$ Thank you GertVdE. I'll just have to look at how exactly the thing with fsolve and functions as parameters works and it'll be done i guess. Thanks again. :) $\endgroup$ – John Dr.Cox Dorian Apr 7 '14 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.