a function of function problem
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Xin CUI
am 29 Apr. 2016
Beantwortet: Walter Roberson
am 29 Apr. 2016
I have an expression f in terms of y (independent variable), a and b(parameters). I would like to take the derivative of f with respect to y, and then set the first order condition df/dy=0 to solve for y. The codes are
function g=derive(y,a,b)
g=diff(fun,y);
end;
function [f,c1,c2]=fun(y,a,b)
f=a*log(c1)+b*log(c2);
c1=y*a;
c2=y*b;
end
y0=1;
y_max=fsolve(g,y0);
I know there are problems in the code. The logic is clear, and I hope someone can tell me how to use function of function (local function or nested function) to solve this problem.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 29 Apr. 2016
Your code will fail at the diff() if y is not symbolic, unless y happens to be 1.
If y is symbolic, then you need to use solve() with g instead of using fsolve() .
Remember to assign a value to g before calling the solving routine. See http://www.mathworks.com/matlabcentral/answers/281617-i-am-having-some-issues-calling-a-function-in-a-script-file#answer_219973
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!