I keep getting the following error "Unable to convert expression into double array" for the code given below, please help

1 view (last 30 days)
THE ERROR:
INPUT:
clear all
clc
syms x1 x2 y1 y2
Q=input('enter the quadratic form Q(x1,x2):');
a11=(1/2)*diff(diff(Q,x1),x1);
a22=(1/2)*diff(diff(Q,x2),x2);
a12=(1/2)*diff(diff(Q,x1),x2);
A=[a11 a12; a12 a22]
A=double(A)
disp('Matrix of Q is')
%disp('Orthogonal matrix (N) reduces A to diagonal matrix D : ')
[N D]=eig(A)
X=[x1;x2];
Y=[y1;y2];
disp('The canonical quadratic form of Q is')
Qy=transpose(Y)*D*Y;
Qy=vpa(Qy,4)
disp('The orthogonal transformation (X=NY) is')
X=vpa(N*Y,4)

Answers (1)

Sriram Tadavarty
Sriram Tadavarty on 30 Jul 2020
Hi Ruban Karthik,
The issue you observe is due to the conversion of symbolic variables to double.
For the input provided, the differential equation contains symbolic variables, thus, it can't be converted to double. Once the symbolic variables are provided with values, you can get rid of the error.
Two suggestions to overcome this:
  1. Comment out A = double(A) and observe all the outputs in symbolic variables
  2. Provide values to A before double A and see the values in the numeric form, by using subs function
Hope this helps.
Regards,
Sriram

Products

Community Treasure Hunt

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

Start Hunting!