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

1 view (last 30 days)
Fernando Piedra
Fernando Piedra on 12 Nov 2020
Answered: Jon on 19 Jun 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 Comment
MANIK
MANIK on 19 Jun 2023
Can you be please more clear regarding your doubt in the code?

Sign in to comment.

Answers (1)

Jon
Jon on 19 Jun 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

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!