필터 지우기
필터 지우기

Use function with symbolic variable within ODE45 in van der pol oscillator problem

조회 수: 2 (최근 30일)
I want to call the second order derivative term as a symbolic function insead of the procedure stated in MATLAB documentation. How can I make this run. Thanks in advance.
%%
clear all
clc
syms t y
[t,y] = ode45(@(t,y)vdp1(t,y),[0 20],[2; 0])
function dydt = vdp1(t,y)
syms p1 p2
EQ1=2*(1-p1^2)*p2-p1;
% dydt = [y(2); 1*(1-y(1)^2)*y(2)-y(1)];
function k= makfun(EQ1,y(1),y(2))
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
k=subs(EQ1,[p1 p2],[y(1) y(2)]);
end
dydt = [y(2); makfun(EQ1,y(1),y(2))];
end

답변 (1개)

Gokul Nath S J
Gokul Nath S J 2022년 10월 21일
Dear Aninda Pal,
There are few ways by which you can use symbolic to find the derivative. Refer to the code below.
syms y(t) dydt(t)
y(t) = t^2 + 2*t + 5;
dydt(t) = diff(y(t));
A sample function of y(t) has been created for the demonstration. If you want to evaluate the derivative at a specific point, say 5, just call dydt(5).
Refer to the attached documentation for more info.

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by