Matlab: Help Solving a 2nd order ODE with the derivative input being a function of time -
i have been going round , round in circles trying matlab solve resonator circuit equation time varying input voltage. works fine long in arguments of derivative functions scalar values.
i have gone through others questions , found answers suggesting anonymous functions or using interpolation. when try implement these suggestions, return error tells me not have enough initial conditions match output of ode function or matrices being concatenated not match..
here code:
%% define parameters f0=1494.72e6; q=80; r=1; l=(q*r)/(2*pi*f0); c=1/((2*pi*f0)^2*l); tp=71e-9; n=2^16; n=(0:n-1); tt=1e-6; h=tt/n; t=n*h; start_pulse=1; end_pulse=round(tp/h); v=zeros(size(t)); %% create voltage pulse ii=1:length(n); if ii>=start_pulse && ii<=end_pulse v(ii)=sin(2*pi*f0*t(ii)); end end %% tspan=[0 tt]; x0=[0 0]; sol=ode45(@ode,tspan,x0,[],v); int=(0:h:tt); sint=deval(sol,int); plot(int,sint*c);
my ode funtion following:
function [ dx ] = ode( t,x,v) f0=1494.72e6; q=80; r=1; l=(q*r)/(2*pi*f0); c=1/((2*pi*f0)^2*l); dx1 = x(2); dx2 =((-x(1)./(l*c))-(r*x(2)./l)-(v./(l*c))); dx = [dx1; dx2]; end
as can see, l,c,and r scalar values. if replace 'v' in dx2 '1', program runs fine. need change v matrix defined above.
any @ appreciated!!! in advance!!! :)
Comments
Post a Comment