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

1 次查看(过去 30 天)
Fernando Piedra
Fernando Piedra 2020-11-12
回答: Jon 2023-6-19
%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 个评论
MANIK
MANIK 2023-6-19
Can you be please more clear regarding your doubt in the code?

请先登录,再进行评论。

回答(1 个)

Jon
Jon 2023-6-19
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

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by