I can not use the " lhs " instruction,but it seems that lots of people can use it.What is the problem ?
1 回表示 (過去 30 日間)
古いコメントを表示
I take this " https://de.mathworks.com/matlabcentral/answers/436044-is-there-anyone-to-help-me-for-lagrange-multipliers-method " as reference of writing the matlab coding of lagrange function,however,when i just copy it into my matlab and simulate,the window said that
Undefined function 'lhs' for input arguments of type 'sym'.
Error in Untitled4 (line 4)
L = A + lambda * lhs(V); % Langrange function
Why will i have this problem?because it seems that there is nobody has this problem when they simulate this file,the matlab version i use is R2015a,is the version problem ?
syms l b h lambda
A = l * b + 2 * b * h + 2 * l * h; % area of needed sheet metal (thickness = 1, because we are lazy guys)
V = l * b * h - 10 == 0; % volume constraint 10 m³
L = A + lambda * lhs(V); % Langrange function
dL_dl = diff(L,l) == 0; % derivative of L with respect to l
dL_db = diff(L,b) == 0; % derivative of L with respect to b
dL_dh = diff(L,h) == 0; % derivative of L with respect to h
dL_dlambda = diff(L,lambda) == 0; % derivative of L with respect to lambda
system = [dL_dl; dL_db; dL_dh; dL_dlambda]; % build the system of equations
[l_val, b_val, h_val,lambda_val] = solve(system, [l b h lambda], 'Real', true) % solve the system of equations and display the results
results_numeric = double([l_val, b_val, h_val,lambda_val]) % show results in a vector of data type double
V_res = l_val * b_val * h_val % calculate the resulting volume (should be 10, if correct)
A_res = l_val * b_val + 2 * b_val * h_val + 2 * l_val * h_val % calculate the needed amount (area) of sheet metal
0 件のコメント
採用された回答
Walter Roberson
2019 年 1 月 25 日
lhs() was not added until R2017a.
In R2012a and later, you can define:
First = @(expr) expr(1);
lhs = @(V) First(children(V));
0 件のコメント
その他の回答 (1 件)
madhan ravi
2019 年 1 月 25 日
https://www.mathworks.com/matlabcentral/answers/438815-why-is-the-lhs-function-including-the-example-posted-in-the-mathworks-documentation-not-working - try everything mentioned in the link
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Biological and Health Sciences についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!