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