- Your function is ‘Euler_Cauchy’, not ‘Sigma_rr’, and since ‘Sigma_rr’ variable is local only to the function, so it doesn’t exist in your workspace;
- The ‘y’ argument is a (2x1) vector so you need to substitute ‘y(1)’ for ‘y’ in the second row in your ODE function matrix (since I assume that is what you intended).
Error in solving second order diff eq. Error in odearguments
1 次查看(过去 30 天)
显示 更早的评论
Hi, I am trying to solve a second order differential equation using ode15s and ode45. The are my scripts and driver files:
Script
% code
%Mechanical Properties of Material
E=200e9;
nu=0.3;
%Constants A,B,C,D in the Equations
a11= (1/E);
a12= (-nu/E);
a33= (1/E);
A= (a12)/(a11+a12);
B= ((a33)-((2*a12^2)/(a11+a12)));
C= (a11)/(a11.^2-a12.^2);
D= (2*a12+a11)/(a11+a12);
%Finding Sigma_rr
O =(D+B*C-A*D);
M = A-2;
function Sigma_rr = Euler_Cauchy(t,y)
Sigma_rr = [y(2); (1/t)*(M*y(2)+O*y)];
end
and
driver file
% tspan = [1 1.2];
y0 = [100000000, 0];
[t,y] = ode15s(@Sigma_rr, tspan, y0);
plot(t,y(:,1))
figure
plot(t,y(:,2))
end
I get the following error message
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode15s (line 150)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in IsotropicThickWallCylinderPlot (line 3)
[t,y] = ode15s(@Sigma_rr, tspan, y0);
I have been on the forums here but have had no luck in figuring out whats wrong. I have terrible matlab skills so any help will be much appreciated.
0 个评论
回答(1 个)
Star Strider
2016-11-29
You have two errors:
This works:
%Constants A,B,C,D in the Equations
a11= (1/E);
a12= (-nu/E);
a33= (1/E);
A= (a12)/(a11+a12);
B= ((a33)-((2*a12^2)/(a11+a12)));
C= (a11)/(a11.^2-a12.^2);
D= (2*a12+a11)/(a11+a12);
%Finding Sigma_rr
O =(D+B*C-A*D);
M = A-2;
Euler_Cauchy = @(t,y) [y(2); (1/t)*(M*y(2)+O*y(1))];
tspan = [1 1.2];
y0 = [100000000, 0];
[t,y] = ode15s(Euler_Cauchy, tspan, y0);
plot(t,y(:,1))
figure
plot(t,y(:,2))
2 个评论
Star Strider
2016-11-30
My pleasure.
The ode15s solver is for stiff initial-value problems. For boundary value problems, you need bvp4c or bvp5c. I have limited experience with them (and none recent), so I can’t suggest code for a specific solution.
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!