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 visualización (últimos 30 días)
% 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 comentarios
Ketha Jaya Sandeep
Ketha Jaya Sandeep el 15 de Dic. de 2019
Editada: Ketha Jaya Sandeep el 15 de Dic. de 2019
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 el 15 de Dic. de 2019
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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by