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

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)

답변 (1개)

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

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

태그

질문:

2020년 7월 30일

댓글:

2020년 7월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by