fsolve syms char double

4 visualizaciones (últimos 30 días)
Andrea
Andrea el 3 de Mayo de 2013
Hello I'm writing a program to solve non linear equations of motion and in particular to determine equilibrium position. Therefore defined the matrices of masses dampers and stiffnesses, I'd like to impose Kz=Q where z is a sym array built with symbolic variables.
thus calling a function to solve this problem i have:
In main
m1 = .1; %[kg]
m2 = 1; %[kg]
L = .5; %[m]
k = 100; %[N/m]
c = 3; %[Ns/m]
c_rot = .05*20; %[Nm/rad]
g = 9.81; %[m/s^2]
alpha=pi/3; %[rad]
F0=12; %[N]
z=[x;theta];
%--------------------------------------------------------------------------
% Non linear system
%--------------------------------------------------------------------------
M=[m1 0;
0 m2*L^2+m1*x^2];
C=[c 0; c_rot c];
K=[k 0; 0 0];
Q=[(m1+m2)*g*sin(alpha); m2*g*L*sin(theta)];
%--------------------------------------------------------------------------
% Linear system
%--------------------------------------------------------------------------
Ml=[];
Cl=[];
Kl=[];
Ql=[];
%--------------------------------------------------------------------------
% Static equilibrium position fron non linear
%--------------------------------------------------------------------------
[zstatic,residuals]=equilibrium4(K,Q,z)
And in the function
function [zstatic,residuals]=equilibrium4(K,Q,z,y)
system2=K*z-Q
n=size(system2,1)
for i=1:n
clear a
a='y('
b=num2str(i)
c=')'
d=[a,'',b,'',c]
system2=subs(system2,z(i),d)
end
F=mat2str(vpa(system2))
h= str2func( ['@(x)' F]);
[zstatic,residuals]=fsolve(h,zeros(n,1))
The problem I encountered is the handling of different types of variables.So I ask you if you can provide me any hint about how to solve this problem in order to make the fsolve work.I tried either calling another function as it's used to be done with input functions but It didn't work as well. Thanks for the attention
  12 comentarios
Andrea
Andrea el 4 de Mayo de 2013
My intention is to substitute to symbolic variables the i-th element of vector y.Vector y is the vector for which system2 is gonna be solved using fsolve, therefore isn't defined, but simply called as an input.Is this possible or I'm going to get stuck?
Walter Roberson
Walter Roberson el 4 de Mayo de 2013
Ah, finally something I can work with...

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 4 de Mayo de 2013
Editada: Walter Roberson el 4 de Mayo de 2013
function [zstatic,residuals]=equilibrium4(K,Q,z)
system2=K*z-Q
h = matlabFunction(system2, 'vars', num2cell(z))
[zstatic, residuals] = fsolve(h, zeros(size(system2,1),1))
  11 comentarios
Walter Roberson
Walter Roberson el 6 de Mayo de 2013
Could you show
size(z)
functions(VecH)
functions(RealH)
and the result of
VecH(ones(1,length(z))
Andrea
Andrea el 6 de Mayo de 2013
Here it is what you asked me
>> size(z)
ans =
2 1
>> functions(VecH)
ans =
function: '@(x)RealH(varscell{:})'
type: 'anonymous'
file: ''
workspace: {[1x1 struct]}
>> functions(RealH)
ans =
function: [1x88 char]
type: 'anonymous'
file: [1x70 char]
workspace: {2x1 cell}
>> VecH(ones(1,length(z)))
ans =
100*x - 2630462507576213/281474976710656
-(981*sin(theta))/200

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by