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

조회 수: 1 (최근 30일)
Muhammad Rohaan
Muhammad Rohaan 2022년 11월 30일
답변: Walter Roberson 2022년 11월 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