How to use fsolve when solving with trapezoidal method?

2 次查看(过去 30 天)
I need help to begin with the function using trapezoidal method and then solving it with fsolve.
should I use an anonymous function or something else?
I'm trying to get a plot of 6 graphs, is the plot correct or should it be in the for_loop?
here is my code please help!
m1=465;
m2=55;
k1=5350;
k2=13610000;
c1=310;
c2=1250;
v0=[0,0,0,0]';
I=eye(4);
V=[0,0,0,0]';
F_prev=[0;0;0;(k2*hfunc(0)+c2*hdotfunc(0))/m2];
A=[0,0,1,0;0,0,0,1;(-k1/m1),(k1/m1),(-c1/m1),(c1/m1);(k1/m2),((-k1-k2)/(m2)),(c1/m2),((-c1-c2)/(m2))];
% Define function to solve for
imptrap = @(V,V_next) (V(i)-V(i+1)+ (s/2)*(A*V(i)+F_prev+A*V_next+F));
l=max(eig(A));
hl=(-2*real(l))/(((real(l)).^2)+(imag(l)).^2);
Vvec=[];
for j=1:3
s=hl*(10^(j-1));
rnditc=round(1/s);
%U=zeros(4,rnditc);
t=0;
tvec=t;
F_prev=[0;0;0;(k2*hfunc(t)+c2*hdotfunc(t))/m2];
for i=1:rnditc
%Beräknar F för varje t
F=[0;0;0;(k2*hfunc(t)+c2*hdotfunc(t))/m2];
%Euler bakåt
V= fsolve(imptrap, v0);
F_prev = F;
%V = V_next;
t=t+s;
Vvec = vertcat(Vvec, V);
tvec=[tvec t];
end
end
plot(tvec(:),Vvec(1,:));
hold on
plot(tvec(:),Vvec(2,:));
hold on
xlabel("Tid")
ylabel("Utslag")
xlim([0 1])
hold on
  2 个评论
Torsten
Torsten 2023-4-26
编辑:Torsten 2023-4-26
I guess nobody in the forum likes to deduce the problem you are trying to solve from the MATLAB code you posted.
So please include a mathematical description of your problem to which we can compare your code.
Mannan
Mannan 2023-8-9
Hi,
The information provided in the description seems to be very limited. Please provide a detail description, including the meaning of the variables.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by