# Minimizing and plotting equations with variables

4 views (last 30 days)
A on 12 Nov 2012
Hello!
This is probably quite a rudimentary question, but I am not familiar with solving equations in matlab, and would greatly appreciate some help.
I have the formula:
f= x*mp + (A-x)*mn - av*A + as*A^(2/3) + ac*x^(2)/A^(1/3) + aa*(x^2 - A/2)^2/A;
where is the variable and all other parameters are taken as constants.
This should minimize to give:
xknot=(A/2)*((mn-mp+aa)/(ac*A^(2/3)+aa));
Then I want to plot the expression
E=f(xknot,A) - m(xknot-2,A-4) - constant
where the brackets imply "as a function of"
I have not even been able to minimize the function in matlab to get the correct xknot defined above.
This is what I have been using so far:
syms x mp mn A av as ac aa
f= x*mp + (A-x)*mn - av*A + as*A^(2/3) + ac*x^(2)/A^(1/3) + aa*(x^2 - A/2)^2/A;
g=diff(f,x);
solve(g)
I do not know how to express the rest of it in matlab.
Thank for your help!
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Answers (1)

Walter Roberson on 12 Nov 2012
You missed an important step in minimization: always also consider the behavior of the function at the extremes of the allowed ranges.
If you examine your function, you will find that except in the region abs(x) <= sqrt(A/2), and once the constant m*(p-n) has been overcome, that the function has opposite signs between negative x and positive x, and that the contributions of x become infinite as x approaches one of the infinities. The signs of A and aa determine which infinity is approached, but you know that the two infinities will be different sign. Therefore, unless x is imposed a restricted range, the minimum of f(x) is -infinity and not the expression you show.
##### 2 CommentsShowHide 1 older comment
Walter Roberson on 12 Nov 2012
Et = subs(f, {x, A}, {xknot, A}) - subs(m, {x, ??}, {xknot, A-4}) - constant;
E = matlabFunction(Et, A);
In the above, replace ?? by the name of the variable in m that is to become A-4 .
Note that you will need to give values to mp mn av as ac aa before you plot. You imply in your question that E should be plottable, so presumably you would have definite values for them by then; you would subs() those definite values in before you used matlabFunction(). Alternately it is possible to tell matlabFunction to make all of those into parameters that need to be passed into the function, and to indicate which order they should appear in.

Sign in to comment.

### Categories

Find more on Linear Algebra in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by