找回密码
 注册
关于网站域名变更的通知
查看: 516|回复: 3
打印 上一主题 下一主题

matlab解常微分一直报错返回列向量

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2021-1-5 10:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

EDA365欢迎您登录!

您需要 登录 才可以下载或查看,没有帐号?注册

x
我的代码解常微分一直说要返回列向量,有大神帮忙看看嘛+ p. L! J( Y8 \* o

6 y2 Y9 A- _5 O% \3 k# H这是代码:1 z9 N, e/ j; u9 x! w: x
function s=mywork(t,y,eta1,eta2,G1,yieldstress,contactstrain,flow,arg)- m/ s$ i5 E! |3 p5 J% W
switch flow
  P& Q+ W5 N/ I9 d! Z8 |! o% Ncase 'creep & recovery'
) ^0 Y7 ~& ?1 B% U# O+ h1 P        stress0=arg(1);% K& w  E$ _% N; B2 S" q# ]4 Z; v3 Z" h
        risetime=arg(2);
/ m0 o( V  R/ l: k- f3 v3 Z8 {0 g1 V! A        creeptime=arg(3);' f& D+ d4 F/ @) c
        if t<risetime" r0 Y2 b0 L8 a
            stressrate=stress0/risetime;7 K1 u; R( c$ x& p) \4 E4 Y
            stress=stressrate*t;$ W% @# G3 @' U/ G& [
        elseif t<creeptime1 R' h+ _7 H7 N- n
            stressrate=0;
, }6 ~! X) n/ U8 ?  C. Y            stress=stress0;0 ^2 G' B2 }# m- Y' i9 V
        elseif t<creeptime+risetime
2 ?& a' ^9 q% l- j1 B3 R- s            stressrate=stress0/risetime;3 p  M' v' d$ [9 n! l
            stress=stress0-stressrate*(t-creeptime);2 Q& L- N# x1 u& I4 E, G$ Y
        else
4 I; f' F! Q( b' y9 B4 V% W            stressrate=0;; {7 c. r: b" W: D1 ]! S+ A9 M
            stress=0;
! K# i) W7 ?2 U+ C        end
0 E4 O2 O7 ~7 A& p2 c- |        gam1=y(1);
8 M4 h8 e1 `% ?3 e+ P6 A: E6 R        gam2=y(2);1 o3 U; w0 k- `
        s(1)=gam2;1 {' j7 B1 F1 n; c$ E
        s(2)=G1/(eta1*eta2*((abs(gam1)-contactstrain)>0))*((stress-eta2*gam2*((abs(gam1)-contactstrain)>0)-sign(stress-eta2*gam2*((abs(gam1)-contactstrain)>0))*yieldstress)*((abs(stress-eta2*gam2*((abs(gam1)-contactstrain)>0))-yieldstress)>0)-eta1*gam2+eta1/G1*stressrate);! f& O# w* _9 R- S; I/ s8 o4 V3 ?

( ~5 y% z7 A7 K  n# m# Z
4 P; L9 R8 |; K2 ]2 S$ U; D: Q9 |6 t" o. a) b  B7 j. C* Z2 @3 e
clear all
# d; _6 \5 ]; |( o% u9 U6 h$ X; _clc2 b) S  f% ?" y- ~, ?$ [
warning off3 y/ S* q3 }& S) R  {

1 Z- D$ u) y5 ^" ceta1=10;  % [Pa.s]
! B7 M7 D0 e- v9 n# H& }1 oeta2=20;  % Pa.s]- E, u% H* a/ G
G1=2;   % [Pa]9 J1 `8 Y2 ?$ H- v& d& h+ w
G2=5;   %[Pa]/ T/ i; f9 R* d9 |8 V! k
yieldstress=5;  % [Pa]+ w! X7 n" v6 R% T- k' J
contactstrain=5;
3 z4 r# s2 m: t/ X% @
1 b$ B' u8 w6 P- A9 Q7 ^* q# G/ F6 j; z2 v- }
flow='creep & recovery';
& F' n, _% [6 {; fstress0=1:2:10;
# h# H6 _! i2 o1 r7 w& ?& h" jrisetime=0.01;% C- V0 M! _7 t: I8 ?! B; z, e: E7 V
creeptime=100;' N# [- G4 m9 A9 [% n
for i=1:length(stress0)
" m/ I+ E8 ^4 G/ g. O6 I* L9 {    [t,strain]=ode15s(@mywork,[0 10],[0 0],[],eta1,eta2,G1,yieldstress,contactstrain,flow,[stress0(i) risetime creeptime]);
& v8 o1 g2 \% m0 F8 a( f( E5 u$ ?5 U    subplot(2,3,3);     semilogx(t,strain(:,1));        hold on
1 ?) _4 y- P* Z, Y; {/ e    a{i}=strcatnum2str(stress0(i),'(Pa)');
4 F) E0 T& _: [+ G1 F! _8 B6 U! @* xend
; H! r; j  ^$ I+ d; _xlin([1e-4 1000]);   9 s0 M3 _$ M6 L7 ], Z# x2 h+ Q  d8 k+ ?
xlabel('Time(s)');      ylabel('Shear strain(-)');
9 }; K( c( f$ Z4 @5 }8 _legend(a)
( f- C1 U4 i' q7 j) ^* B( {1 g1 C; W, {; o7 p( e  V* r

, q* n0 G+ t" N7 J* G3 B) ~. Y' \# f( Y% T1 b& z  E
错误使用 odearguments (第 93 行)
, |1 l) K. g. ~# D; `9 [( bMYWORK 必须返回列向量。
, `0 w4 N4 J7 _4 {* X- O+ t3 o- p8 ^# y, Y6 Z: ?. u9 X
出错 ode15s (第 152 行)9 w; v) Z* C6 Y( x
    odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);0 H2 Q! j; K; W  f, Z% R. Y

$ k5 H$ X' U2 ~! t* A; p6 V出错 Untitled2 (第 20 行)7 ^) \" @- [$ L0 P
    [t,strain]=ode15s(@mywork,[0 10],[1 0],[],eta1,eta2,G1,yieldstress,contactstrain,flow,[stress0(i) risetime creeptime]);  p8 K' ^% I! G; @7 x
8 H5 |1 L0 A8 F1 N/ b& ?$ I

9 I" Y4 q7 ^) s: }感谢大神们!
* P* W, W- D1 c4 Q; y! l8 [# T

该用户从未签到

2#
发表于 2021-1-5 13:09 | 只看该作者
clear all
' V( j. J$ y1 G' W3 `- }+ \clc
' R6 q8 U) ]/ u1 S; fwarning off6 [0 l) T- t0 D7 r) a
& E4 l' v  r; X$ z+ S
eta1=10;  % [Pa.s]
3 F7 u# s- H# aeta2=20;  % Pa.s]
6 T2 X% O) c. A5 L& d. aG1=2;   % [Pa]
5 s! c4 p+ N3 X3 Y% n, IG2=5;   %[Pa]9 M/ q. I  F1 @% z( m
yieldstress=5;  % [Pa]$ v, F# i9 K5 T
contactstrain=5;
; n1 v- o" p: R% {1 S6 ~4 i2 N! Y; }# a8 [, z, ^
  W3 p: \- P' K7 j' H+ L
flow='creep & recovery';5 {5 R" F: A. p0 v1 F
stress0=1:2:10;
" w) W6 p+ e; u; U1 G6 erisetime=0.01;
" P$ n' Q# w  p4 C* mcreeptime=100;. t* N, u1 R; F; P: X
for i=1:length(stress0)& P4 g, d1 X9 U4 O( M  Q, E
    [t,strain]=ode15s(@mywork,[0 10],[0 0],[],eta1,eta2,G1,yieldstress,contactstrain,flow,[stress0(i) risetime creeptime]);
' u3 ]. r2 C$ a! [' g9 q* f    subplot(2,3,3);     semilogx(t,strain(:,1));        hold on
' R3 h6 ]) i6 l0 V0 m& A  j    a{i}=strcat(num2str(stress0(i)),'(Pa)');' L( m  e9 @/ \: m4 ~# `
end
( Z. _* q) f& Mxlim([1e-4 1000]);
. s/ p6 h6 G2 F- d( E" dxlabel('Time(s)');      ylabel('Shear strain(-)');. p& s8 Y* R' R. Q- ]& R1 h, s& v
legend(a)& I7 {% U3 v" O' `# R( @
function s=mywork(t,y,eta1,eta2,G1,yieldstress,contactstrain,flow,arg)0 y. m0 C* B! Y% [; ?
switch flow
+ F1 C( [) q- |, g! A) m& F8 M5 S    case 'creep & recovery'
/ A! S% H% M* I        stress0=arg(1);" h6 N/ l  e1 X& |% ~; V2 z- `
        risetime=arg(2);  Y9 F$ A  _$ ]) A2 Q3 }, H
        creeptime=arg(3);
; ]7 ^: T1 I/ U9 @$ d' x( @        if t<risetime! }5 i- @% e9 A6 t' _$ y& O
            stressrate=stress0/risetime;: m# R  g# f7 b: }
            stress=stressrate*t;2 c1 p/ X/ f& x/ z" Z0 x& F: f3 W
        elseif t<creeptime( M# \- n. T1 v* }" b+ b
            stressrate=0;
1 V4 y: T) o! I, @  n+ u' R            stress=stress0;) O3 i+ @/ h2 r
        elseif t<creeptime+risetime4 {# N% w# V# L& v
            stressrate=stress0/risetime;+ U$ T/ B* _, W8 |7 `1 t
            stress=stress0-stressrate*(t-creeptime);  J8 y, S  Q1 X
        else
$ u6 c+ F$ g9 W# R8 C            stressrate=0;
8 \- E( G7 N4 D1 R            stress=0;
. l6 B  p& ~6 n2 D" d7 b$ o) r, f9 u        end0 C( K" g' F- a! _# t5 }1 a" U, }( Q
        gam1=y(1);
1 x( ]  \% p# Z) X% C% b        gam2=y(2);
& _) Z- Z3 m- ^* W        s(1)=gam2;6 p5 o, o) M8 `9 U: s) V
        s(2)=G1/(eta1*eta2*((abs(gam1)-contactstrain)>0))*((stress-eta2*gam2*((abs(gam1)-contactstrain)>0)-sign(stress-eta2*gam2*((abs(gam1)-contactstrain)>0))*yieldstress)*((abs(stress-eta2*gam2*((abs(gam1)-contactstrain)>0))-yieldstress)>0)-eta1*gam2+eta1/G1*stressrate);3 w2 n! L3 V( Q( D
        s=s';: V" o+ S6 W6 j8 ]1 G9 _
end
0 Q  B# V- f/ T. f  o: w/ @end

该用户从未签到

4#
发表于 2021-1-5 15:43 | 只看该作者
来学习一下
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

推荐内容上一条 /1 下一条

EDA365公众号

关于我们|手机版|EDA365电子论坛网 ( 粤ICP备18020198号-1 )

GMT+8, 2025-8-3 11:37 , Processed in 0.109375 second(s), 23 queries , Gzip On.

深圳市墨知创新科技有限公司

地址:深圳市南山区科技生态园2栋A座805 电话:19926409050

快速回复 返回顶部 返回列表