I am trying to plot freq vs max(x)/max(y) values for the following data. But I am having an error as shown below.Can anyone help me with this.

조회 수: 1 (최근 30일)
% file 1
for f=1:100
t = [0:0.01:2];
x0 = [0;0];
[t,x]=ode23('for1', t, x0);
[val,idx] = max(x) ;
fr(f)=f;
val(f)=val;
hold on
end
plot(fr,val/0.001,'*r')
%file 2
function f = for1(t,x)
c = 376.9900;
k = 7.1061e+05;
Y = 0.001;
f=zeros (2,1);
f(1) = x(2);
f(2) = -(c*x(2)/5)-(k.*x(1)/5)+((k/5).*Y.*sin(2.*pi.*f.*t))+( (c/5).*Y*2*pi.*f.*cos(2*pi.*f.*t));
end
Unable to perform assignment because the
left and right sides have a different
number of elements.
%ERROR
Error in for1 (line 8)
f(2) =
-(c*x(2)/5)-(k.*x(1)/5)+((k/5).*Y.*sin(2.*pi.*f.*t))+(
(c/5).*Y*2*pi.*f.*cos(2*pi.*f.*t));
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I
sets args{1} to yp0.
Error in ode23 (line 114)
odearguments(FcnHandlesUsed,
solver_name, ode, tspan, y0, options,
varargin);
Error in test1 (line 4)
[t,x]=ode23('for1', t, x0);
Required Output:
  댓글 수: 3
Ketha Jaya Sandeep
Ketha Jaya Sandeep 2019년 12월 15일
편집: Ketha Jaya Sandeep 2019년 12월 15일
Thank you Mr.Jesus Sanchez for your support.
I rectified that error, but I am encountering a new error with the following code.
x0 = [0;0];
for f=1:100
for tspan=0:0.01:2
[t,x]=ode23('for1', tspan, x0);
end
[val,idx] = max(x) ;
fr(f)=f;
val(f)=val;
hold on
end
plot(fr,val,'*r')
ERROR
Error using odearguments (line 83)
The last entry in tspan must be different from the first entry.
Error in ode23 (line 114)
odearguments(FcnHandlesUsed,solver_name, ode, tspan, y0, options,varargin);
Error in test1 (line 4)
[t,x]=ode23('for1', tspan, x0);
Jesus Sanchez
Jesus Sanchez 2019년 12월 15일
I am sorry, I have never worked with ode23 before, so I am not sure how to help you further :(. From the error message, it seems that tspan must be a vector, so you will have to work under this assumption and modify your function consequently.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by