How to use fsolve when solving with trapezoidal method?

2 views (last 30 days)
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 Comments
Torsten
Torsten on 26 Apr 2023
Edited: Torsten on 26 Apr 2023
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 on 9 Aug 2023
Hi,
The information provided in the description seems to be very limited. Please provide a detail description, including the meaning of the variables.

Sign in to comment.

Answers (0)

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!