i have a set of values for the force term "F" (in the equation my"+cy'+ky=F) saved in an excel file which i have recalled using:
F=xlsread('l&d.xlsx','O1:O300');
My main code looks something like:
y0=initial conditions
[tsol ysol]=ode15s('beam_function',[1:dt:T],y0);
plot(tsol,ysol);
whereas, my function code looks something like:
function [dy]=beam_function(t,y)
dy=[y(1:u-1);
inv(M)*(F-K*y(u:end)-C*y(1:u-1))]
The problem is that i want to recall each value of F at different time steps but i dont know how to do that, can anyone guide me?
Note: F here is not time dependent rather it has been taken from results obtained from a simulation software. Then what should be my approach?

 Risposta accettata

darova
darova il 24 Ago 2021
You need to pass F into your ode function. Read more: LINK
for i = 1:length(F)
[t,y] = ode45(@(t,y)beam_function(t,y,F(i)),...)
end
function dy = beam_funciton(t,y,F)

6 Commenti

Bhanu Pratap Akherya
Bhanu Pratap Akherya il 24 Ago 2021
Modificato: darova il 25 Ago 2021
that helped, i have one more question
here is my main code:
clear all
clc
Ne=6;
l=1; %length
t=0.02; %thickness
b=0.02; %width
modulus=2e11; %(E)
area=b*t;
imoment=(b*((t)^3))/12;
Le=l/Ne; %length of element
Rho=7850; %density
%Element stiffness matrix
K1=(modulus*imoment/(Le^3))*[12,6*Le,-12,6*Le; ...
6*Le,4*Le*Le,-6*Le,2*Le*Le; ...
-12,-6*Le,12,-6*Le; ...
6*Le,2*Le*Le,-6*Le,4*Le*Le];
Kglobal=zeros(2*(Ne+1),2*(Ne+1));
M1=[156 22*Le 54 -13*Le;...
22*Le 4*Le*Le 13*Le -3*Le*Le;...
54 13*Le 156 -22*Le;...
-13*Le -3*Le*Le -22*Le 4*Le*Le]*(Rho*Le*b*t)/420;
Mglobal=zeros(2*(Ne+1),2*(Ne+1));
for ii=1:Ne
Kglobal(2*ii-1:2*(ii+1),2*ii-1:2*(ii+1))=Kglobal(2*ii-1:2*(ii+1),2*ii-1:2*(ii+1))+K1;
Mglobal(2*ii-1:2*(ii+1),2*ii-1:2*(ii+1))=Mglobal(2*ii-1:2*(ii+1),2*ii-1:2*(ii+1))+M1;
end
K=Kglobal;
K(1:2,:)=[];
K(:,1:2)=[];
M=Mglobal;
M(1:2,:)=[];
M(:,1:2)=[];
C=0.05*Kglobal;
C(1:2,:)=[];
C(:,1:2)=[];
K
M
C
u=(2*Ne)+1;
%dt=1/(max_freq*20);
dt=0.001;
T=300;
%Displacement initials
y0=zeros(2*(2*(Ne+1))-4,1);
% y0(1:2,:)=[];
% y0(u:u+1,:)=[];
y0(end-1,1)=0.5;
% t_array = a(1,:); % This is t array from xls file
F=xlsread('l&d.xlsx','O1:O300'); % This is F array from xls file
%% ode solver
for i = 1:length(F)
[tsol ysol]=ode15s(@(t, y) beam_function(t, y, F(i), K, M, C, u),[1:dt:T],y0);
end
ysol(:,u:end)=[];%eliminate velocity nodes 5001*12
size(ysol)
ii=1:2:(u-2); %eliminate angular displacement nodes
ysol(:,ii+1)=[]; %eliminating angular dis components
size(ysol)
%% plotting
plot(tsol,ysol(:,Ne))
here is my function
function [dy]=beam_function(t, y, F, K, M, C, u)
dy=[y(u:end);
M\(F-K*y(1:u-1)-C*y(u:end))]
I want force (F) to be applied on the last node. Can you tell me a way how i can do that?
Did you try simply?
F(end) = 1000;
Bhanu Pratap Akherya
Bhanu Pratap Akherya il 25 Ago 2021
No, but won't this simply change my F matrix's last term to 1000?
darova
darova il 25 Ago 2021
Exactly. Isn't that enough?
Bhanu Pratap Akherya
Bhanu Pratap Akherya il 25 Ago 2021
No, I meant how to apply the current F matrix on only the last column of y in ODE. Right now it is being applied on all the columns of y.
darova
darova il 29 Ago 2021
Modificato: darova il 29 Ago 2021
Maybe you need another ode function
function [dy]=beam_function(t,y)
n = numel(y);
dy(n/2) = y(end);
dy(end) = inv(M)*(F-K*y(end)-C*y(end));
And solve it separately

Accedi per commentare.

Più risposte (0)

Categorie

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by