MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
Asked by Saeed Althamer on 25 May 2013

I've tried all means to get to bring both F1 and F2 to near-zero value. Any help please in this?

this is the code:

function F=myfun(x) cc=x(1); kc=x(2); md=-2; kd=-2000; w=1100; alpha=.5; m=0.01; mr=0.1; k=3000; kr=1000; c=0.1; cr=0.002;

d=(-mr*w^2+(2*kc+kr)+2*cc*cos(alpha*pi/2)*w^alpha)^2 + (2*cc*sin(alpha*pi/2)*w^alpha+cr*w)^2 ;

nm=(mr*kr*(-mr*w^2+(2*kc+kr)+2*cc*cos(alpha*pi/2)*w^alpha)) + mr*cr*w*(2*cc*sin(alpha*pi/2)*w^alpha+cr*w); f1=md-(m+(nm/d));

nk=(kr*kc+kr*cc*cos(alpha*pi/2)*w^alpha-cr*cc*sin(alpha*pi/2)*w^(alpha+1)) * (-mr*w^2+(2*kc+kr)+2*cc*cos(alpha*pi/2)*w^alpha)... +(cr*kc*w+cr*cc*cos(alpha*pi/2)*w^(alpha+1)+kr*cc*sin(alpha*pi/2)*w^alpha) * (2*cc*sin(alpha*pi/2)*w^alpha+cr*w);

f2=kd-(k+nk/d); F=[f1;f2]; ################################

and then in the command window:

options=optimset('MaxIter',50000,'MaxFunEvals',100000,'TolFun',1e-10); x0=[1 1]; [result, fval]=fsolve(@myfun,x0,options)

Any ideas how to solve this issue? thanks in advance

*No products are associated with this question.*

Answer by Matt J on 25 May 2013

Edited by Matt J on 25 May 2013

Well, for starters, it might help somewhat if you rewrite your equations as

(md-m)*d - nm = 0

(kd-k)*d - nk = 0

This way, f1 and f2 become simple quadratic functions of the unknowns, or so it looks to me. Now, it is certainly possible that simultaneous quadratics may have no solution, as FSOLVE seems to be finding. Or, it's possible that you've just chosen a bad x0.

You could plot f1 and f2, e.g., using SURF, to see if there is a solution and if so, where a good choice of x0 would lie.

## 2 Comments

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/76957#comment_150940

Any ideas how to solve this issue?Please post what you mean by "this issue". What is the outcome you see (e.g., the values of x and F) when you run the code?

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/76957#comment_150945

hey Matt

well, actually the issue is regarding not having the two functions to be near zero so I could accept the results as valid solution for the system of the nonlinear equations. And this is what I get when I run this code:

No solution found.

fsolve stopped because the last step was ineffective. However, the vector of function values is not near zero, as measured by the selected value of the function tolerance.

criteria details

result =

fval =

here in the fval, ideally i'd have zero values for both functions. The second function, however, is zero which is great. But, the first function is -2.0008 which is far from zero, hence, the result is NOT valid. i'm trying to make both to be near zero and get the values of the two variable that I'm looking for.