sym to double data type:

2 visualizaciones (últimos 30 días)
Bamelari Jovani
Bamelari Jovani el 14 de Ag. de 2024
Respondida: Walter Roberson el 14 de Ag. de 2024
I want to obtain the y_values in double but they are in symbolic form. Anyway I can get around this? Thank you!
L_e = 0.7199;
Y_poly = @(x) a4*x.^4 + a3*x.^3 + a2*x.^2 + a1*x + a0;
x_values = linspace(0, L_e, 100); % 100 points from 0 to L_e
y_values = Y_poly(x_values);
The values for the coefficients are:
a4 = -0.324785
a3 = 0.472768
a2 = -0.011102
a1 = 0.000000
a0 = 1.000000
  2 comentarios
Paul
Paul el 14 de Ag. de 2024
y_values are alread double based on the posted code.
a4 = -0.324785;
a3 = 0.472768;
a2 = -0.011102;
a1 = 0.000000;
a0 = 1.000000;
L_e = 0.7199;
Y_poly = @(x) a4*x.^4 + a3*x.^3 + a2*x.^2 + a1*x + a0;
x_values = linspace(0, L_e, 100); % 100 points from 0 to L_e
y_values = Y_poly(x_values);
y_values(1:5)
ans = 1x5
1.0000 1.0000 1.0000 1.0000 1.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
class(y_values)
ans = 'double'
Torsten
Torsten el 14 de Ag. de 2024
There is nothing symbolic in what you posted.
a4 = -0.324785;
a3 = 0.472768;
a2 = -0.011102;
a1 = 0.000000;
a0 = 1.000000;
L_e = 0.7199;
Y_poly = @(x) a4*x.^4 + a3*x.^3 + a2*x.^2 + a1*x + a0;
x_values = linspace(0, L_e, 100); % 100 points from 0 to L_e
y_values = Y_poly(x_values);
plot(x_values,y_values)
grid on

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 14 de Ag. de 2024
Your coeffiecients are symbolic. You should use
syms x
Y_poly = matlabFunction(a4*x.^4 + a3*x.^3 + a2*x.^2 + a1*x + a0);

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by