P(t)=25sin(35t) euler method

1 visualización (últimos 30 días)
Fernando Piedra
Fernando Piedra el 12 de Nov. de 2020
Respondida: Jon el 19 de Jun. de 2023
%i need help with my getder file which take the derivative of the funtion.
%there are 3 file main where define all variables getder which i obtain the derivative
%and box_solve to solve and create a plot using eulers or RK method.
%Many thanks in advance
%main file
v0 = 0;
s0 = 0;
m = .5;
k = 75;
%getder file to obtain a the derivative
function xdot = getder(t,x)
x = [s;v];
a = (1/m)*(25*sin(45*t)-k*so);
xdot = [s;a];
%box_solve file to solve equation through euler method or Rk.
function [t,x] = box solve(x0,tlim,dt,solve_type)
if st == 1 %solve type allow operator to
t = (to:dt:tf).'
L = length(t);
x = xeros([l,2])
x(1,:) = xo.'
for n =1:L
x(n+1,:) = x(n,:)+dt*geter(t(n),x(n,:));
  1 comentario
MANIK
MANIK el 19 de Jun. de 2023
Can you be please more clear regarding your doubt in the code?

Iniciar sesión para comentar.

Respuestas (1)

Jon
Jon el 19 de Jun. de 2023
Just glancing at your code I can see a number of errors:
The variable s is not defined anywhere before you call this line of code in getder
x = [s;v];
So, MATLAB will not know how to make that assignment since it doesn't know what s is.
In the next line of code
a = (1/m)*(25*sin(45*t)-k*so);
It looks like you have a variable called so (also not defined) you probably meant s0 (that's the number zero as the second character rather than the letter o)
In this line you do not use a valid name for the function. You can not have spaces in a function name.
function [t,x] = box solve(x0,tlim,dt,solve_type)
You probably have even more errors but that should at least get you started

Categorías

Más información sobre Mathematics 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