フィルターのクリア

CAT arguments dimensions are not consistent while using eval command of symbolic jacobian

1 回表示 (過去 30 日間)
Thayumanavan
Thayumanavan 2014 年 2 月 17 日
編集済み: Thayumanavan 2014 年 4 月 10 日
syms x1 x2
%The Diffenrential Equation
f1= (x1)+(x2*x2);%x1dot Equation
f2=x1-x2; % x2dot Equation
f = [f1, f2];
% Forming the symbolic jacobian
Jac = jacobian(f)
x1=0.0;
x2=1.0;
% eval is used to convert the symbolic jacaobian to numeric jacobian
% Finding the eigen values of the Numeric jacobian
q=eval(Jac)
e=eig(q)
Jac =
[ 1, 2*x2]
[ 1, -1]
q =
1 2
1 -1
e =
1.7321
-1.7321
If i use the above code as a function to calculate the eigen values of the sol of ode45 solver as follows:
Main Program:
clear all
clc;
Tspan =[0 1];
X0=[0.0; 1]; % Initial condition
%solving the differential Equation
[t,x]=ode45(@myfunc,Tspan,X0);
%Plotting the figures
figure(1)
subplot(2,1,1)
plot(t(:,1),x(:,1))
xlabel('t');
ylabel('x1');
grid on
subplot(2,1,2)
plot(t(:,1),x(:,2))
xlabel('t');
ylabel('x2')
grid on
% Finding the eigen values
e=findeig(x)
First Function (Ode function)
function dv=myfunc(t,x,flag)
%The Diffenrential Equation
dv=[ (x(1))+(x(2)*x(2));%x1dot Equation
x(1)-x(2); ]; % x2dot Equation
Second Function to calculate eigen value of x:
function e=findeig(x)
syms x1 x2
%The Diffenrential Equation
f1= (x1)+(x2*x2);%x1dot Equation
f2=x1-x2; % x2dot Equation
f = [f1, f2];
% Forming the symbolic jacobian
Jac = jacobian(f)
x1=x(:,1);
x2=x(:,2);
% eval is used to convert the symbolic jacaobian to numeric jacobian
% Finding the eigen values of the Numeric jacobian
q=eval(Jac)
e=eig(q);
It is giving the following output with error:
x =
0 1.0000
0.0001 0.9999
0.0001 0.9999
0.0002 0.9998
0.0002 0.9998
0.0005 0.9995
0.0007 0.9993
0.0010 0.9990
0.0012 0.9988
0.0025 0.9975
0.0037 0.9963
...... (57x2 array)
Jac =
[ 1, 2*x2]
[ 1, -1]
??? Error using ==> horzcat
CAT arguments dimensions are not consistent.
Error in ==> sym.eval at 15
s = evalin('caller',vectorize(map2mat(char(x))));
Error in ==> findeig at 11
q=eval(Jac)
Error in ==> MainProgram at 23
e=findeig(x)
I am expecting the jacobian elemnts has to be replaced with x
for example:for the first row
Jac =
[ 1, 2*1]
[ 1, -1] and has to give eigen value as
1.7321
-1.7321
and so on for all rows of x.why eval is not working for array of elememts

回答 (1 件)

Christopher Creutzig
Christopher Creutzig 2014 年 3 月 31 日
編集済み: Christopher Creutzig 2014 年 3 月 31 日
Don't use eval on syms. Preferably, don't ever. Better use subs as in
q = double(subs(jacobian(f), {x1, x2}, {x(:,1), x(:,2)}));
(You can of course split that on multiple lines. It's just my personal preference not to.)
  7 件のコメント
Walter Roberson
Walter Roberson 2014 年 4 月 8 日
If you want the first row first element to be assigned to x1, then do not pass in the entire column x(:,1), only pass in the single element x(1,1)
Thayumanavan
Thayumanavan 2014 年 4 月 10 日
編集済み: Thayumanavan 2014 年 4 月 10 日
for i=1:Length q = double(subs(Jac,{x1, x2},{x(i,1),x(i,2)})); e=eig(q); end
Length is the array size .
As per ur idea i used a for loop as above and got the answer.Thanks sir

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeNumbers and Precision についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by