Error using solve function

15 ビュー (過去 30 日間)
Muhammad Rohaan
Muhammad Rohaan 2022 年 11 月 29 日
コメント済み: Muhammad Rohaan 2022 年 11 月 29 日
solve function for code
Gives the error: unable to find explicit solution.
x1 = input('Input volume of tank in gallons: ');
x2 = x1/7.48;
syms int_l;
cost = 812.745*(2*int_l.^2+4.*(int_l+0.5)*(y./(int_l.^2)+1));
diff_cost = diff(cost);
answ = solve(diff_cost == 0);
int_l = answ(isAlways(answ>0));
int_l = double(int_l);
int_h = x2/(int_l.^2);
ext_l = int_l + 1;
ext_h = x2./(int_l.^2)+1;
disp('----------------------------------------------------------------')
disp(['Length of the internal height in feet will be: ' num2str(int_l)])

採用された回答

Steven Lord
Steven Lord 2022 年 11 月 29 日
You have two variables in your cost function, y and int_l. Is y symbolic or a fixed value? If symbolic, with respect to which variable do you want to differentiate the cost?
syms int_l y;
cost = 812.745*(2*int_l.^2+4.*(int_l+0.5)*(y./(int_l.^2)+1));
diff_cost = diff(cost)
diff_cost = 
diff_cost_y = diff(cost, y)
diff_cost_y = 
diff_cost_int_l = diff(cost, int_l)
diff_cost_int_l = 
The expressions diff_cost and diff_cost_y depend only on int_l but diff_cost_int_l depends on both int_l and y. If you're trying to solve diff_cost_int_l == 0, with respect to which variable are you trying to solve?
solve(diff_cost_int_l, int_l)
ans = 
solve(diff_cost_int_l, y)
ans = 
  1 件のコメント
Muhammad Rohaan
Muhammad Rohaan 2022 年 11 月 29 日
it seems that i was taking a wrong variable. Thanks a lot.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by