fsolve syms char double
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Walter Roberson
am 4 Mai 2013
Bearbeitet: Walter Roberson
am 4 Mai 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 Kommentare
Walter Roberson
am 6 Mai 2013
Could you show
size(z)
functions(VecH)
functions(RealH)
and the result of
VecH(ones(1,length(z))
Siehe auch
Kategorien
Mehr zu Data Type Identification finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!