Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Fernando Piedra
Fernando Piedra le 12 Nov 2020
Réponse apportée : Jon le 19 Juin 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 commentaire
MANIK
MANIK le 19 Juin 2023
Can you be please more clear regarding your doubt in the code?

Connectez-vous pour commenter.

Réponses (1)

Jon
Jon le 19 Juin 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

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by