필터 지우기
필터 지우기

ode with varying constant

조회 수: 17 (최근 30일)
prajyot gajbhiye
prajyot gajbhiye 2020년 10월 21일
답변: Star Strider 2020년 10월 21일
i have one differntial eqation and in that i have two constants one is scalar and one is vector i have to solve diffential equation for each value of vector means i got no of diff equation= no of elements in vector now i have to plot each solution of each de with time
function [dydt] = diffvar(t,y)
dydt=-k*y+a;
end
  댓글 수: 3
prajyot gajbhiye
prajyot gajbhiye 2020년 10월 21일
but you have considered both as scalar
Ameer Hamza
Ameer Hamza 2020년 10월 21일
That code will work even if you put one of the variable as scalar.

댓글을 달려면 로그인하십시오.

답변 (1개)

Star Strider
Star Strider 2020년 10월 21일
Interpolating a time-domain vector in a differential equation is essentially described in the ode45 (and other solvers) documentation. This simply re-states it in the context of the current problem.
Try this
ic = 0;
tspan = [0 10];
k = 42;
av = rand(1,10); % Vector Defining ‘a’
a = @(t) interp1(linspace(min(tspan),max(tspan),numel(av)), av, t); % Function Interpolating ‘a’
[T,Y] = ode45(@(t,y)diffvar(t,y,k), tspan, ic);
figure
plot(T, Y)
grid
function [dydt] = diffvar(t,y,k)
dydt=-k*y+a(t); % Call ‘a’ As A Function
end
Use your own vector for ‘av’ and your own constant for ‘k’.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by