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

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

[复制链接]

该用户从未签到

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

EDA365欢迎您登录!

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

x
我的代码解常微分一直说要返回列向量,有大神帮忙看看嘛+ D+ F! s% `: N* J- Y; C

! u8 w4 ^/ _, f; h. B# L- S这是代码:" U' u) ?; q' E
function s=mywork(t,y,eta1,eta2,G1,yieldstress,contactstrain,flow,arg)0 u- `) l6 d! \  z* U7 }! J+ a
switch flow1 Z( h9 X$ ^$ I+ x* R3 f  O' F- g
case 'creep & recovery'5 X5 A" S/ m' ~0 Z# F5 h3 o
        stress0=arg(1);
: z3 W' W) R/ Y, V! b6 r( v        risetime=arg(2);  E2 ~0 ]+ W0 o( m+ M
        creeptime=arg(3);9 B) m0 j, }7 o, k
        if t<risetime
8 c4 _7 `- w) s3 \  u            stressrate=stress0/risetime;
3 j+ H5 b* p& \) b            stress=stressrate*t;$ f7 k4 ~- N! ]' F$ q: _5 `6 z, f
        elseif t<creeptime
1 }' Z, h; a& A& ]) q$ n            stressrate=0;% p3 P9 W( R8 w: a4 m0 {* y
            stress=stress0;' c2 V6 s% D' q5 z" O& g8 J
        elseif t<creeptime+risetime1 I* D# V: [5 W7 a6 r
            stressrate=stress0/risetime;+ s, O; w( T4 M
            stress=stress0-stressrate*(t-creeptime);
. |; w# i- _; R  Z4 c- ^; m        else& c- m# s4 b$ Q5 K8 H
            stressrate=0;
3 |5 H3 x- V) ~9 X- o( F6 S            stress=0;
# k9 f7 \/ m* {& w0 `4 z        end
+ _# g* b+ P/ a  o* H  m        gam1=y(1);
$ g- ~. f. k/ r. B. K5 |+ ?( R$ B        gam2=y(2);2 _3 n. I+ E, X# h8 ~  y% W$ E
        s(1)=gam2;. t' V% d2 A% K7 P( M; m
        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);" X( z7 h6 ?/ |4 x- S, }; y

  }, g& o! R/ A. E7 ?1 q1 l8 m! R# C$ g# X  N

" K) s  W0 ^  L4 u" g' t* U. Rclear all0 q+ D9 i$ ^2 `& F1 w
clc4 B2 j( P( h$ a. W) k, t+ }- E. v/ v
warning off
) H: Y5 S0 p/ j+ J
6 l+ j& m% F0 u8 y1 ueta1=10;  % [Pa.s]
  z) q8 T" U5 Q' E, U2 v6 veta2=20;  % Pa.s]
! c( G: _% z) q' @* E) QG1=2;   % [Pa]
+ R2 O! X* X( D6 {$ oG2=5;   %[Pa]
( F8 q9 A0 q4 s" v; ]yieldstress=5;  % [Pa]
) J" x/ h: M) a' ?: ?contactstrain=5;2 e# ?8 U8 C" S; m  ]

+ H2 a5 _" y- K5 v, w# j" D  w8 I
3 I7 A$ r2 O9 Q) G+ D  sflow='creep & recovery';
* t4 W9 T" W/ m9 J5 O& ustress0=1:2:10;; [7 o: {1 h2 v' E* x. m
risetime=0.01;( Z  h: o# D% B$ A/ X
creeptime=100;
  ?: }( r8 V, Z: K) s6 mfor i=1:length(stress0)3 p. k8 `0 b7 {- W
    [t,strain]=ode15s(@mywork,[0 10],[0 0],[],eta1,eta2,G1,yieldstress,contactstrain,flow,[stress0(i) risetime creeptime]);0 T4 J5 I8 a  h7 k' r; p: G3 V2 n- a
    subplot(2,3,3);     semilogx(t,strain(:,1));        hold on
5 J$ ?! l2 O3 j    a{i}=strcatnum2str(stress0(i),'(Pa)');
# a, M2 o& m$ R* _0 @; a$ Aend
/ [& l: c* T9 G/ V( p/ Qxlin([1e-4 1000]);   
* E! K- J. K8 I& J' _6 I7 z4 G* Pxlabel('Time(s)');      ylabel('Shear strain(-)');
% {! }: @4 A9 z8 q" V; P+ rlegend(a)$ j4 E4 d) J5 j8 W8 d
+ A/ I9 g, f' e. h8 d" \

: `- ~- n( C6 Q6 I7 [, M- l& `4 F
6 I% V* r4 k- k: q# |  o错误使用 odearguments (第 93 行)
! i9 ?; n9 B: n( l7 n5 Q1 [MYWORK 必须返回列向量。( ~7 [3 I5 z; n) J; t. [

1 v* @  l% D* z9 o$ i. e出错 ode15s (第 152 行): L9 _$ y8 h8 Q% A- e" q
    odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);* `, f! B6 N7 w) N- Y& _- _) k
0 J' g; t4 v. u7 x: I& F7 S
出错 Untitled2 (第 20 行)
, D0 |+ R# X% e8 e* u    [t,strain]=ode15s(@mywork,[0 10],[1 0],[],eta1,eta2,G1,yieldstress,contactstrain,flow,[stress0(i) risetime creeptime]);
7 K& T& J  I6 s
. e6 G* M- p9 l. [
$ n4 D/ d8 Y8 i4 C& _( j+ D# _感谢大神们!
- ^( I+ X0 r+ l1 ~* m, v, d

该用户从未签到

2#
发表于 2021-1-5 13:09 | 只看该作者
clear all
, I9 U; O- v: lclc0 o% W3 P2 F& V  m% r
warning off
4 @3 c! B0 |# x
7 l9 K1 q5 t0 g! reta1=10;  % [Pa.s]* ^9 s8 d3 S. H
eta2=20;  % Pa.s]
$ V$ @! V, w' [* c4 m! ]G1=2;   % [Pa]8 W& }1 U, M4 S! g: ~8 `
G2=5;   %[Pa]7 L' ^. R* c0 ^
yieldstress=5;  % [Pa]1 H7 O9 C1 `/ _% c( }/ c: M4 w
contactstrain=5;
- Y7 B! S4 u9 Y+ F& f. s
- r! _0 U  y9 `
. P) {# A. j& f/ V: U8 A+ Z" Eflow='creep & recovery';
5 Q" L6 P6 H4 p0 X4 {, n4 Ystress0=1:2:10;9 o5 x' R4 p2 {$ _; w
risetime=0.01;) G- _$ Q# b/ T4 i) g
creeptime=100;
1 p- f; L2 z& A( S. Afor i=1:length(stress0)
! _8 ^2 V7 W! ^1 m& d5 X    [t,strain]=ode15s(@mywork,[0 10],[0 0],[],eta1,eta2,G1,yieldstress,contactstrain,flow,[stress0(i) risetime creeptime]);# g4 q; C3 t% w/ N$ ^2 R
    subplot(2,3,3);     semilogx(t,strain(:,1));        hold on
4 i! m* e2 u2 P2 w' X: y4 ?9 A$ B    a{i}=strcat(num2str(stress0(i)),'(Pa)');
+ U: `5 i8 \( F- I7 C5 H$ o% x; Nend3 Q. C5 X0 ?/ h, g* v
xlim([1e-4 1000]);
2 @0 J6 q0 ?8 ^. ?. V+ H0 qxlabel('Time(s)');      ylabel('Shear strain(-)');
1 o' k& [% x/ @& l7 Blegend(a)
! w( f# o0 i+ g0 g+ @function s=mywork(t,y,eta1,eta2,G1,yieldstress,contactstrain,flow,arg)! a; J5 E6 i, e( x4 Q
switch flow4 a" T% r+ I2 _8 b+ ^
    case 'creep & recovery'8 J; b6 V3 h4 g; \2 a+ f8 `
        stress0=arg(1);- K2 j& F1 ]8 x
        risetime=arg(2);6 k4 ?9 [( E* H8 q2 a0 h1 L6 B
        creeptime=arg(3);
+ y; H. ]* c5 M        if t<risetime) P( k- ~$ T( c. C4 d7 f3 ^
            stressrate=stress0/risetime;
) n% p: O  r, {# q6 k9 h" m            stress=stressrate*t;
  f9 H# j& t$ h" m9 w! i0 J        elseif t<creeptime
& P8 G$ B& G( \5 |- @9 Y            stressrate=0;
& x/ J5 y+ V& w: ^$ _; j            stress=stress0;
+ |, ?' j7 u* w$ C" j        elseif t<creeptime+risetime( p4 G# I. C0 w
            stressrate=stress0/risetime;( m; L# L. B% |' b$ j
            stress=stress0-stressrate*(t-creeptime);* g! K/ o  ]) X4 Y+ w, T" \: {+ c
        else) P, p# Y0 @' B9 W- [0 ~
            stressrate=0;0 q" g! y8 \, \! x! n; _
            stress=0;& I  |1 y) j1 s5 d; s
        end& Z' Y, R* j6 c% b( J1 r# X
        gam1=y(1);5 h1 O' R7 n/ Q/ P  ]! D  \
        gam2=y(2);( G5 H. k! e4 u! l
        s(1)=gam2;
% M4 j+ w# T7 s" I( A        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);
' S7 ~+ q0 }1 s! T( L) ~        s=s';" Q) r6 A: s1 Q
end
8 z2 j& t' ~' e& h- _  q, Qend

该用户从未签到

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

本版积分规则

关闭

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

EDA365公众号

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

GMT+8, 2025-7-20 20:24 , Processed in 0.109375 second(s), 23 queries , Gzip On.

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

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

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