Clear Filters
Clear Filters

Solve with multiple values

2 views (last 30 days)
Daniel
Daniel on 22 Oct 2011
Below is the equation I'm trying to work with. g is a single value. vbprime, newtheta and y1 are 1x51 matrices. I just want to solve for t1, for use in c, but I can't seem to get it to solve. I keep getting an error about MUPAD engine in the solve line. I have declared t1 to by sym also. I expect c to S to have multiple values, as well as c. Any thoughts?
S=-0.5*g.*t1^2+vbprime.*sind(newtheta).*t1+y1
solve(S)
c=(100-vbprime.*cosd(newtheta).*t1)

Accepted Answer

Walter Roberson
Walter Roberson on 22 Oct 2011
syms t1 vbprime_ newtheta_ y1_
S=-0.5*g.*t1^2+vbprime_.*sind(newtheta_).*t1+y1_;
T1 = solve(S,t1);
T1Fun = matlabFunction(T1, vbprime_, newtheta_, y1_);
c = arrayfun(@(IDX) 100-vbprime(IDX).*cosd(newtheta(IDX)) .* T1Fun(vbprime(IDX), newtheta(IDX), y1(IDX)), 1:length(vbprime));
  5 Comments
Walter Roberson
Walter Roberson on 23 Oct 2011
Hmmm... the function is a quadratic, so there are two solutions coming out of solve(). Possibly matlabFunction is interpreting that as requiring two output arguments.
Unfortunately as I do not have the toolbox, this is not something I can test for myself.
I would suggest that you would be better off solving the quadratic algebraically once (using the quadratic formula) on paper, and either choosing one of the two roots based upon additional information, or else creating both formula and handling them semi-independently.
For both together, I get
t3 = sin(newtheta .* pi / 180);
t4 = vbprime .* t3;
t5 = vbprime .^ 2;
t6 = t3 .^ 2;
t11 = sqrt(t5 .* t6 + (2 .* g .* y1));
t13 = 1 ./ g;
s1 = (t4 + t11) .* t13;
s2 = (t4 - t11) .* t13;
Daniel
Daniel on 25 Oct 2011
Holy cow I got it. Not exactly sure why it works, but it works. I included the code below for future questions. Thanks so much for all your help. Quadratic equation!!! A little different then what you suggested, but same idea. I should have thought of this. Thanks so much again!
a=-0.5*g
b=vbprime.*sind(newtheta)
c=y
t=(-b-sqrt(b.^2-4.*a*c))/(2*a)

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!