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

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

[复制链接]

该用户从未签到

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

EDA365欢迎您登录!

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

x
我的代码解常微分一直说要返回列向量,有大神帮忙看看嘛! \; Z5 J4 F+ V; J. G( W
+ C1 ^7 M) ]& A) z7 t$ v& B
这是代码:6 V% v8 D0 ~& V1 y4 k8 ^3 {% a
function s=mywork(t,y,eta1,eta2,G1,yieldstress,contactstrain,flow,arg)
: [* r* ?' Q! l# o6 s: j7 p0 U0 W* f9 \switch flow
# y5 _1 Y$ Q  L) J5 zcase 'creep & recovery'* ^, R0 o! H$ x- ]* L
        stress0=arg(1);. ~& E7 e- u6 s+ D+ \8 d7 V- S2 v# U
        risetime=arg(2);
4 L  N+ j8 l& i/ [  e        creeptime=arg(3);
8 ?( m, [, F; O. U        if t<risetime
/ C7 E. k" y* n8 R            stressrate=stress0/risetime;
1 t) _$ C% P/ f- q5 ^. ^            stress=stressrate*t;
' X  d% Q7 k/ g2 M" c- N4 u" V9 m        elseif t<creeptime: S+ h0 q7 Z" P% n# k. ^
            stressrate=0;" k/ c# `9 @# H# R/ @4 S" X! }
            stress=stress0;
7 E  H! V% ?; ]/ y- Z* C+ z        elseif t<creeptime+risetime
- U7 F# j0 i  B            stressrate=stress0/risetime;$ X! J2 p+ w7 ~, T8 L1 P# S5 W, z
            stress=stress0-stressrate*(t-creeptime);
) d+ l; `( D$ z        else$ X; n2 V# z; o8 F# F2 I
            stressrate=0;0 D0 X6 r7 Q4 e) s' ^- U
            stress=0;0 w: r  a, D7 g# v1 _. l+ N
        end" X7 `- t. o( E7 w' [, l8 ?/ m) [! Q
        gam1=y(1);+ z+ S- S) P4 u/ V# U6 j8 J# t
        gam2=y(2);+ \: M- N! c3 p8 j8 I# ?
        s(1)=gam2;
$ F! [% Z8 l9 S/ z        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);
. C2 }( p6 u8 Q" r  m
: G. d, Y% b( ~9 P, L6 |+ n4 m! s+ {% V7 m% u! K4 H1 t0 m

( O; X, C3 b) k/ O( b# oclear all
. Z0 f' x9 z6 B+ K  `+ z/ V/ Nclc
8 j' _  U# H0 Awarning off
  X9 [* \+ b; |# p: i! {- ]% n# \
eta1=10;  % [Pa.s]
5 N, v0 x6 `3 O( R7 x3 eeta2=20;  % Pa.s]9 F4 I  u3 m* n+ R) y* D4 V8 D
G1=2;   % [Pa]. S! v5 i2 x  Q' \' g
G2=5;   %[Pa]
, i) C& Q  C8 K6 qyieldstress=5;  % [Pa]
. {- P$ ?5 p1 j, ?2 D( ^4 |7 {" jcontactstrain=5;
4 b* W6 I" k$ |" J3 s7 k; a6 K0 ~; T4 T" x) p) U( J
& _4 j7 |  K5 G6 L
flow='creep & recovery';5 M: F* v4 a% B& r4 e" v
stress0=1:2:10;  K- c  |: V0 M' x& V
risetime=0.01;
& g$ J% {" ?% U3 R. _6 v! m" U' rcreeptime=100;5 x9 o  K: e% o# Y" p1 t
for i=1:length(stress0)
# }1 v+ [/ {" W" Y" h. n7 Q    [t,strain]=ode15s(@mywork,[0 10],[0 0],[],eta1,eta2,G1,yieldstress,contactstrain,flow,[stress0(i) risetime creeptime]);1 ?  x, \1 I6 e9 D
    subplot(2,3,3);     semilogx(t,strain(:,1));        hold on
, H. o8 |3 h! X) x    a{i}=strcatnum2str(stress0(i),'(Pa)');
6 s3 D7 }3 `# H* H9 I) iend
1 Y# F* _( C# M9 I2 f" B4 p" M& txlin([1e-4 1000]);   * }9 }- ^9 F+ h) S/ a
xlabel('Time(s)');      ylabel('Shear strain(-)');
( F9 G& _! [9 v0 s6 _" v# ]( l3 Zlegend(a)
4 _3 y) n; z( E5 G- v/ y8 [
% Y- R, p& Z. D7 ?$ [) P: z$ `4 ~% ?* P8 p0 V- W; Y( t6 }+ k
2 e- Y$ _# l9 K( Z) J. T3 W
错误使用 odearguments (第 93 行)8 \9 E  M5 m! B6 P
MYWORK 必须返回列向量。
; l+ d, S9 [) {4 u/ w; ~+ k* O& q% L/ l: t+ M) L
出错 ode15s (第 152 行)& G. U$ F, x7 c9 b9 l
    odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
' p0 {: O* w0 o* Y8 h; r
% A0 @) H! H* y; D出错 Untitled2 (第 20 行)
2 @! n; ~* G# H- Y$ p    [t,strain]=ode15s(@mywork,[0 10],[1 0],[],eta1,eta2,G1,yieldstress,contactstrain,flow,[stress0(i) risetime creeptime]);& R8 o% L4 Y8 v* b2 o; ~
. B' d; a& Z# ^

  J0 c  l. a2 g& ^+ g) M感谢大神们!
2 v$ Q5 ]- h$ b4 D8 C7 r: y

该用户从未签到

2#
发表于 2021-1-5 13:09 | 只看该作者
clear all
: M& }! E2 y' M) v2 k- f+ Rclc2 g4 R9 b  F; `1 @# P0 b
warning off
5 k2 I, z7 t. L9 d: Q0 P9 z6 _5 I& d$ L+ L  m% J  z; _
eta1=10;  % [Pa.s]
/ w5 L: }: J1 E+ U( C% ?& H" ^6 Leta2=20;  % Pa.s]
/ p5 d* B- Y' A7 q/ `- H- n; W+ L8 iG1=2;   % [Pa]
/ q7 e/ z4 W2 C8 TG2=5;   %[Pa]# a2 i) j7 v$ U! E9 A/ e
yieldstress=5;  % [Pa]
. U9 ?7 x! c9 I' hcontactstrain=5;# H; _% s" F: C1 Z+ h: c; l% X

; v: V1 l. `- a3 B. @& _& ?; V  N, j+ U3 `& V7 U
flow='creep & recovery';
5 }/ c3 H! J, C+ b9 @4 Xstress0=1:2:10;4 C0 a, H9 J% |
risetime=0.01;
, c) W0 p5 U) a* {% Screeptime=100;
. x5 d7 U" V4 z. t% {for i=1:length(stress0)
; v; V3 G; A) w# V9 M# n& m/ A    [t,strain]=ode15s(@mywork,[0 10],[0 0],[],eta1,eta2,G1,yieldstress,contactstrain,flow,[stress0(i) risetime creeptime]);
8 J, Y9 f4 f# L5 k5 R    subplot(2,3,3);     semilogx(t,strain(:,1));        hold on9 z  J+ C% q: S1 _/ N% A
    a{i}=strcat(num2str(stress0(i)),'(Pa)');  N- f- {+ J' K- O0 U( v0 W
end
- X; }+ `: f+ d( t5 r1 [! dxlim([1e-4 1000]);
& c; B  B' W. t" yxlabel('Time(s)');      ylabel('Shear strain(-)');1 N4 o- N' j6 T' @7 @; M& [: ]
legend(a)
: q  a5 d) ^( {( E4 Efunction s=mywork(t,y,eta1,eta2,G1,yieldstress,contactstrain,flow,arg)
9 T+ Z5 m0 ]4 V% Y! Iswitch flow
# R3 t' \5 W" L3 z8 y    case 'creep & recovery'
0 O) s. I: r+ j8 W: r$ G8 A" \        stress0=arg(1);
# p/ S+ F0 ?: w( k8 Y1 f        risetime=arg(2);
& ?8 v, O, x+ v/ R/ _        creeptime=arg(3);5 n, k$ ~, d8 @( l& W
        if t<risetime+ @8 y8 w, b  K- g
            stressrate=stress0/risetime;  v, K0 ~: w7 n2 u: e
            stress=stressrate*t;
  q0 d" \3 x7 e! x- o; F) z; ]        elseif t<creeptime2 ]1 J$ L9 R! z- M8 B! S
            stressrate=0;
7 t1 ~  g7 b# b/ n7 B            stress=stress0;
% Y- P5 O- y2 W9 v7 D2 ]        elseif t<creeptime+risetime. Y* _9 u3 b$ d+ k3 D6 O% o/ ]
            stressrate=stress0/risetime;
+ X# {. s: h2 n! h; Z& E- k. N            stress=stress0-stressrate*(t-creeptime);# M# }' K) p$ L, |3 Y8 E3 O$ v
        else
' d' N) i5 ?8 H; ^; B9 G' W% U            stressrate=0;
4 _1 x* B/ c, t9 X+ H, q3 O            stress=0;% [4 P2 b: f: ]) z2 i$ o5 b
        end* Y3 R. y- }6 h
        gam1=y(1);
2 D( d7 K, u  r" b2 A4 S/ c        gam2=y(2);
/ h, }) n" Z/ X6 P! D% {; P        s(1)=gam2;. b9 y) O* E( j% b
        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);2 p3 p4 f% \$ q- `) I
        s=s';: g, _, }  H$ t) P
end+ L8 U6 P, u' q
end

该用户从未签到

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

本版积分规则

关闭

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

EDA365公众号

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

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

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

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

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