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

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

[复制链接]

该用户从未签到

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

EDA365欢迎您登录!

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

x
我的代码解常微分一直说要返回列向量,有大神帮忙看看嘛
( S2 F+ ]7 q4 [  r0 |: F! V/ v8 G. @5 I1 v+ m
这是代码:
- I8 s$ i9 y# u2 m3 Dfunction s=mywork(t,y,eta1,eta2,G1,yieldstress,contactstrain,flow,arg)* e. T# d. s' G: C" T* k( X# W
switch flow8 i' A2 i$ T8 g) h
case 'creep & recovery'
0 e  y# l; D6 R8 q. a0 Z. T( N% P1 v        stress0=arg(1);
9 b! \: A3 s. y2 x3 U        risetime=arg(2);
# n" h. f9 h6 B7 s( N; g% M& u        creeptime=arg(3);
( N9 O1 B( k& `4 b5 j# H- m        if t<risetime% ]  `8 I+ f; A; J* y- Y
            stressrate=stress0/risetime;) {, V; I) I  t$ d7 b3 e
            stress=stressrate*t;2 I1 ~- n" f0 W. a, a2 X
        elseif t<creeptime
, n# _# T3 f$ \8 n            stressrate=0;" E8 N) ]& S% W' p4 ~5 k2 [* d9 ~) z
            stress=stress0;
# ]% s6 T2 e- N% y        elseif t<creeptime+risetime5 R6 m' K9 ~, T6 Y. h. [# A* ~
            stressrate=stress0/risetime;( _- L3 D5 V; B- c& k- A
            stress=stress0-stressrate*(t-creeptime);0 \! w- B, g$ ~* S8 H& i8 b+ n2 V- l
        else! P3 w' R! {" V* r7 A+ V
            stressrate=0;
$ R% I! y4 k8 g$ B+ b. B4 i            stress=0;9 C3 w. ?# {* v* _$ G: A
        end6 j/ |1 q  w3 W, u
        gam1=y(1);8 ^  z4 M8 l! t
        gam2=y(2);! Y  Q/ w' ?9 r2 `. J, g4 r% v
        s(1)=gam2;; G2 O/ H7 K2 ~* w# a* {3 u
        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);- y0 }  N& `+ V5 M

( T  O) {2 v3 N3 O5 Q3 q+ E! q; u& L# e2 ?/ v! i

5 p% M; l/ k" X9 r) `clear all2 X0 a+ t, \9 g& {
clc& f2 J! t! h7 ^. T1 u9 [
warning off  K# A# E  Y/ |/ M/ l

; j7 Q/ b: ^, x0 v5 |eta1=10;  % [Pa.s]
/ E( Z: z# y0 |! ^3 [* U4 q; ueta2=20;  % Pa.s]
3 \! G. g. s9 uG1=2;   % [Pa]0 U1 \9 O3 J2 P" ^' |
G2=5;   %[Pa]
$ d# o% ~$ g; E7 v6 ]* Zyieldstress=5;  % [Pa]
  z+ U1 o" }: F7 w. Z* ^2 Fcontactstrain=5;
4 n( e/ U6 z; A2 t2 I* T" T, C9 |" E. U" l5 U- o
- z1 S9 _" X7 i! U4 f
flow='creep & recovery';
1 Z5 w& S# z; `stress0=1:2:10;& o, y/ ?' B7 u6 Z& s0 c7 |9 s
risetime=0.01;$ l& _6 o0 Y& c' i7 }
creeptime=100;
7 [* z' P3 ]( h, h/ B' p# Gfor i=1:length(stress0). {* h7 H$ C# @' h. m
    [t,strain]=ode15s(@mywork,[0 10],[0 0],[],eta1,eta2,G1,yieldstress,contactstrain,flow,[stress0(i) risetime creeptime]);
: G9 p( x9 Z7 q9 b" G# H) T    subplot(2,3,3);     semilogx(t,strain(:,1));        hold on% O* W; O' v! B/ U4 w
    a{i}=strcatnum2str(stress0(i),'(Pa)');
( a1 {6 R9 b; V# d4 n$ A! W9 q0 Tend
/ A! Y$ [% U" }xlin([1e-4 1000]);   8 j# E5 s' _' w' C! z9 A% K
xlabel('Time(s)');      ylabel('Shear strain(-)');
6 M# O% s9 T! i$ Flegend(a)
, k. r- {( d( l' a! d
+ \% E4 Q8 ^% q7 M
# @: I$ m$ V7 W, A* }$ G6 t0 S9 R5 c9 n( L0 l/ v) j) W4 n7 ^
错误使用 odearguments (第 93 行)8 p; P+ `8 @4 S' B
MYWORK 必须返回列向量。+ C7 C! L6 A* ^3 W

$ t/ ]% k$ ^6 f( V. }( w2 w出错 ode15s (第 152 行)* g# [; }) D& i8 d$ V
    odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);+ v9 ]+ @& ]* n" M+ V/ L

( W3 |# l8 {* b) O& o& c- N出错 Untitled2 (第 20 行)* h2 v/ W  C: r/ O
    [t,strain]=ode15s(@mywork,[0 10],[1 0],[],eta1,eta2,G1,yieldstress,contactstrain,flow,[stress0(i) risetime creeptime]);
8 f1 ~: p$ s: K& E- [! j. a1 o
) D, O) K' F# o  P" s! V+ F% [' I* z$ x! {, S
感谢大神们!
, g9 y0 W0 i7 _- |" D

该用户从未签到

2#
发表于 2021-1-5 13:09 | 只看该作者
clear all& e* ~* S+ ~# u. b4 z  V' V
clc1 c- B; S3 {0 O  Y2 ?6 X2 V
warning off  V1 q3 ?2 n. g' e  V/ ]

2 B" `2 H2 }" c+ ^eta1=10;  % [Pa.s]: o5 p3 ~& x; ]
eta2=20;  % Pa.s]
3 u+ ]8 l3 @6 `. c- x. ~3 D( u1 j  D0 DG1=2;   % [Pa], P# D2 U, ?0 {3 T  P4 s
G2=5;   %[Pa]2 w; p1 }( ?7 z
yieldstress=5;  % [Pa]2 S- e* z7 b1 d
contactstrain=5;
" W" J% E; [2 T
' p+ ~0 R: g2 `; k9 [
) ]: C- \$ W0 r8 h$ k4 vflow='creep & recovery';! C! k# p1 @% S& w
stress0=1:2:10;
) l3 V1 h- t$ o2 b& g; d0 C4 c% x& Qrisetime=0.01;
& d6 N5 g0 E# e9 K5 r5 \creeptime=100;# Y) z/ z  b- T  \
for i=1:length(stress0); _. Q- [. Y' t9 ?+ D- P
    [t,strain]=ode15s(@mywork,[0 10],[0 0],[],eta1,eta2,G1,yieldstress,contactstrain,flow,[stress0(i) risetime creeptime]);
8 y' c9 Z1 o1 s( ~9 j& @    subplot(2,3,3);     semilogx(t,strain(:,1));        hold on2 ]6 L4 i/ j* ^
    a{i}=strcat(num2str(stress0(i)),'(Pa)');2 F+ w+ I; ], _+ D( V# z
end
7 l) b1 d, e/ D+ k* k* G6 bxlim([1e-4 1000]);
) D4 G: w6 v, x, r. {$ hxlabel('Time(s)');      ylabel('Shear strain(-)');
+ w$ x1 }6 [" T& F- u0 O5 olegend(a)
2 a$ c% p) `# efunction s=mywork(t,y,eta1,eta2,G1,yieldstress,contactstrain,flow,arg)
' r1 |) D, A$ g; X1 M, fswitch flow) f2 ~5 l. E; W7 |6 ?$ H
    case 'creep & recovery'
" I: d9 {% k3 C5 I" X        stress0=arg(1);
+ E/ W( g- g/ l% J4 e        risetime=arg(2);5 D( I( a9 g* F/ a" Q; D; _
        creeptime=arg(3);1 d) H; M0 q' A6 ?! E
        if t<risetime
. S6 V) w. B0 }) D/ W- e            stressrate=stress0/risetime;
) g5 _% v+ F/ O/ \- l+ d            stress=stressrate*t;
) L3 V4 p. S7 V5 a4 }        elseif t<creeptime& m6 {+ Z. g4 J9 V
            stressrate=0;- a6 S( V* Z8 w7 h5 t! l
            stress=stress0;) g8 f3 Z" _5 d' c
        elseif t<creeptime+risetime
4 b; B, D: U, g1 e# A            stressrate=stress0/risetime;
' P* X0 ?+ j& s. A' A( r7 R6 f% }5 h            stress=stress0-stressrate*(t-creeptime);
- i  N9 n0 R5 d6 I; Y        else
/ i; m4 [! Y% x; `            stressrate=0;
+ D4 o  Z: K2 E3 h" L2 B- F            stress=0;4 c1 ?$ W. a0 W  {5 i  N/ g
        end2 H* t' F% ^2 R" {* h! G  z
        gam1=y(1);( Z: u4 H' K! r9 ]8 \
        gam2=y(2);! V9 j7 C" W; \$ G5 S
        s(1)=gam2;: D- h/ b* W& h
        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);
  H9 C# N' k! x1 a$ i        s=s';
- o# a9 S9 l: l3 @' Vend6 c. t* w/ i! a, h' U2 E3 A9 j
end

该用户从未签到

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

本版积分规则

关闭

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

EDA365公众号

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

GMT+8, 2025-11-24 01:17 , Processed in 0.140625 second(s), 23 queries , Gzip On.

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

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

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