How to use fsolve when solving with trapezoidal method?

조회 수: 2 (최근 30일)
Ilyan Njim
Ilyan Njim 2023년 4월 26일
댓글: Mannan 2023년 8월 9일
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