f =
Unable to obtain double precision from symbolic value
Mostra commenti meno recenti
Hello everyone,
MATLAB returns a symbolic value for x(1,1). How do I go about converting it into a double precision?
Thank you!
clear;
clc;
close all;
%% Initial parameters %%
radian_to_deg = 180/pi;
degree_to_radian = pi/180;
prompt = "Enter a Mach Number ranging from 1.5 to 4: ";
Me = input(prompt);
prompt_1 = "Enter the number of divisions: ";
n_div = input(prompt_1);
prompt_2 = "Enter the throat radius: ";
TR = input(prompt_2);
g = 1.4;
mach_angle= [];
theta = [];
theta_a = [];
y=[];
x=[];
v=[];
v_a=[];
%% get mach angle
ma_f = @(x) asind(1/x) ;
%x = Me;
%ma_angle = ma_f(x);
%% get theta_max
A = sqrt((g+1)/(g-1));
B = (g-1)/(g+1);
pm_f = @(x) (A*atand(sqrt(B*(x^2-1))) - atand(sqrt(x^2-1)));
theta_max = pm_f(Me)/2;
%% extraction of fractional part of theta_max
%dT = theta_max/n_div;
%theta(:,1) = (dT:dT:theta_max);
theta_i = sign(theta_max)*(abs(theta_max) - floor(abs(theta_max)));
%{
for i = 2:n_div
theta(i,1) = theta(i-1,1) + 3.0;
end
%}
%% Storing different values of theta_a
%point a
for i = 1:n_div
theta_a(i,1) = theta_i ;
theta_i = theta_i + 3.0;
end
v_a = theta_a;
%% Getting properties of a and 1
ya=1;
xa=0;
%theta_a(1,1) = theta_i(1,1);
v_a(1,1) = theta_a(1,1);
%point 1
y(1,1) = 0;
Km_1 = theta_a(1,1) + v_a(1,1);
theta(1,1)= 0.5*(Km_1);
v(1,1) = 0.5*(Km_1);
%% get mach number for v(1,1)
syms x
f = @(x) (A*atand(sqrt(B*(x^2-1))) - atand(sqrt(x^2-1))-v(1,1));
f1 = matlabFunction(diff(f(x)));
%NR Method using a while loop
change = 10;
Mguess = 1.1;
while (change>1e-6)
Mnew = Mguess - f(Mguess)/f1(Mguess);
change = abs(Mguess - Mnew);
Mguess = Mnew;
end
mach_angle(1,1) = ma_f(Mnew);
x(1,1) = (-ya/tand(theta(1,1)-mach_angle(1,1)))
Risposta accettata
Più risposte (1)
Ayush Modi
il 18 Lug 2024
Modificato: Ayush Modi
il 18 Lug 2024
Hi Bamelari,
You can convert the symbolic value into double precision value using double method. Here is a sample code to demonstrate this:
syms a b x
a = sym(3);
b = sym(2);
x = a / b;
disp(x); % This will display 3/2 (symbolic form)
% Convert the symbolic result to double precision
x_double = double(x);
disp(x_double);
For more information on double method, refer to the following MathWorks documentation:
2 Commenti
Bamelari Jovani
il 18 Lug 2024
Ayush Modi
il 18 Lug 2024
You need to convert the symbolic variable to double. Right now, even though you are using double, you are still assigning the value to symbolic variable.
To get the final value in double precision, modify the code as below -
x(1,1) = -ya/tand(theta(1,1)-mach_angle(1,1));
double_x = double(x(1,1));
% Note that double_x is a new variable
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!