Solve with multiple values

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)

 채택된 답변

Walter Roberson
Walter Roberson 2011년 10월 22일

0 개 추천

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

Daniel
Daniel 2011년 10월 22일
Well dang! That was fast, thank you very much. I'm still trying to figure it out, I'm not very good at MatLab functions. However, it didn't work. I ran into this same problem in one of my own attempts. It says:
??? Undefined function or method 'sind' for input arguments of type 'sym'.
Which seems odd because solving for an angle is so common. I'm reading the chapter on functions now, any quick fixes? Thanks so much again. In any event, I'm much closer to my answer.
Walter Roberson
Walter Roberson 2011년 10월 22일
I would not say that I am surprised. For sind(theta) substitute sin(theta*Pi/180); likewise cosd(theta) is cos(theta*Pi/180)
Daniel
Daniel 2011년 10월 23일
No, that didn't work either. I get this four line error warning,(see below) and that's just from removing the 'd' to make it work in radians. I tried the sub you mentioned, got the same thing. I don't understand the function part enough to tweak it. Thanks so much for your help though, I really do appreciate it. I'll keep working on it when I can, but thanks again.
??? Error using ==> deal at 38
The number of outputs should match the number of inputs.
Error in ==>
sym.matlabFunction>makeFhandle/@(newtheta_,vbprime_,y1_)deal([sqrt(y1_.*(1.6087e4./2.5e2)+vbprime_.^2.*sin(newtheta_).^2).*(5.0e2./1.6087e4)+vbprime_.*sin(newtheta_).*(5.0e2./1.6087e4);sqrt(y1_.*(1.6087e4./2.5e2)+vbprime_.^2.*sin(newtheta_).^2).*(-5.0e2./1.6087e4)+vbprime_.*sin(newtheta_).*(5.0e2./1.6087e4)],vbprime_,newtheta_,y1_)
Error in ==> @(IDX)100-vbprime(IDX).*cos(newtheta(IDX)).*T1Fun(vbprime(IDX),newtheta(IDX),y1(IDX))
Error in ==> Copy_of_CP05_P2 at 59
c=arrayfun(@(IDX) 100-vbprime(IDX).*cos(newtheta(IDX)).*T1Fun(vbprime(IDX), newtheta(IDX), y1(IDX)), 1:length(vbprime))
Walter Roberson
Walter Roberson 2011년 10월 23일
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 2011년 10월 25일
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)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by