Error using plot, data must be numeric, array convertible to double

1 次查看(过去 30 天)
Why is it giving error for the last line to plot?
Error using plot: data must be numeric datetime duration or an array convertible to double.
I want to plot the graph for cost and internal length
x1 = input('Input volume of tank in gallons: ');
x2 = x1/7.48;
syms int_l;
cost = (2*int_l.^2+4.*(int_l+0.5)*(x2./(int_l.^2)+1))*812.75;
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);
disp('----------------------------------------------------------------')
disp(['Length of the internal square base of the tank in feet will be: ' num2str(int_l)])
disp(['Length of the internal height of the tank in feet will be: ' num2str(int_h)])
ext_l = int_l + 1;
ext_h = x2./(int_l.^2)+1;
disp('----------------------------------------------------------------')
disp(['Length of the external square base of the tank in feet will be: ' num2str(ext_l)])
disp(['Length of the external height of the tank in feet will be: ' num2str(ext_h)])
plot(cost,int_l);
grid on;

回答(1 个)

Walter Roberson
Walter Roberson 2022-11-30
syms int_l;
int_l is symbolic
cost = (2*int_l.^2+4.*(int_l+0.5)*(x2./(int_l.^2)+1))*812.75;
cost is in terms of symbolic int_l so cost will be symbolic.
You do not change cost after that, so it is still symbolic when you get to
plot(cost,int_l);
However, there is no plot function defined for symbolic expressions. There is a fplot function for symbolic expressions. When you use fplot() if you provide a second parameter then the second parameter must be the range of values to do the plotting over.

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by