フィルターのクリア

How to use fsolve when solving with trapezoidal method?

1 回表示 (過去 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 Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by