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

2 views (last 30 days)
Muhammad Rohaan on 30 Nov 2022
Answered: Walter Roberson on 30 Nov 2022
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;

Walter Roberson on 30 Nov 2022
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.