Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Function of matlab.
2 ビュー (過去 30 日間)
古いコメントを表示
Could you please explain to me the general Idea how to write a function in matlab?
I was wrote code for original queistion which is f(x)=-2x^2+Lx If the Constraints x is in the feasible set [0,L/2] and it's work with me. But I'm not sure how to make a derivation If the df/dx= -2x + L;
And how can I write a function that numerically solves df/dx = -4x+ L=0
0 件のコメント
回答 (2 件)
Star Strider
2017 年 4 月 28 日
編集済み: Star Strider
2017 年 4 月 28 日
For numeric functions, see the documentation on Function Basics (link). For Symbolic Math Toolbox functions, see the documentation on Create Symbolic Functions (link) in R2012a and later versions.
Example —
syms L x
f(x) = -2*x^2 + L*x
dfdx = diff(f)
x_sol = solve(dfdx == 0)
f(x) =
- 2*x^2 + L*x
dfdx(x) =
L - 4*x
x_sol =
L/4
You can create anonymous functions (or function files) from them with the matlabFunction function that will do numeric calculations in MATLAB not using the Symbolic Math Toolbox. See the documentation on the various functions for details.
0 件のコメント
Image Analyst
2017 年 4 月 28 日
Numerically you can make an x with, say, a hundred thousand points or whatever.
x = linspace(0, L/2, 100000);
Now make the derivative:
dfdt = -4 * x + L; % or -2 * x + L, whatever one you're solving for.
Now find the element where it's closest to zero
[minValue, index] = min(abs(dfdt));
Now use that index to get the x value and f(x) value - I assume you know how to do that. Depending on L, and what equation you're using, there may be no solution.
0 件のコメント
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!