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

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

[复制链接]

该用户从未签到

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

EDA365欢迎您登录!

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

x
我的代码解常微分一直说要返回列向量,有大神帮忙看看嘛4 Y- `3 v- Z. e; G6 R; [7 k, w

% ^3 f( M, o& [8 }% a& b  E. ?这是代码:4 _- y" A" d+ X! n1 l4 i+ }4 n4 O
function s=mywork(t,y,eta1,eta2,G1,yieldstress,contactstrain,flow,arg)7 I: f% A: q& {$ T  W& D( ~* J
switch flow4 S7 P8 [( @7 u! S
case 'creep & recovery'
( L/ ^0 B% O! o        stress0=arg(1);
5 J# a% f! Z" s3 L! t! m        risetime=arg(2);
% c8 n  z* A( h' I0 B2 W2 X! x5 W        creeptime=arg(3);5 P8 I6 E# T0 h' L* @: `# G+ r
        if t<risetime
( A. A1 G: I$ H# B: [9 \            stressrate=stress0/risetime;8 o: l/ c& l4 f0 `9 `# }
            stress=stressrate*t;+ _- M3 _# [: E: G) A0 ~
        elseif t<creeptime3 ]2 O9 l5 o2 N6 M* ~6 |) E6 D
            stressrate=0;
7 O+ j' g1 b7 l            stress=stress0;
( ~8 K7 a$ Q0 @7 e/ r3 a# F5 x        elseif t<creeptime+risetime
% V; N; J4 F2 i) z" J2 g            stressrate=stress0/risetime;
! c3 X& @7 S' d' f* s' x! V            stress=stress0-stressrate*(t-creeptime);0 [8 w0 b! _5 ?* q
        else
5 b/ E+ G9 c( u& X            stressrate=0;
( @" F; e5 F* ~3 M  z            stress=0;3 C: M: K% f( E' S) ]1 U9 _/ M6 w
        end$ H3 ^% {0 ]* c5 ]* @! I8 I: I+ N
        gam1=y(1);
& l. b* E! y" F- a        gam2=y(2);8 P: ^% c2 p$ L+ D2 T: B
        s(1)=gam2;
6 c% T  A4 l! P/ N- n3 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);; B/ C& D' u/ m: p5 B; l

/ \; z- G, F: S2 T1 ~6 q# t5 D1 I( [& k6 x+ c8 o  v

1 _3 D( p. P# ^, b8 Q' _clear all1 @5 t) `* }( p' I7 F) M$ V* m
clc
; e2 F) f( K+ X: i. Nwarning off
" `2 ?$ {+ H5 c+ d& ?. P/ Z9 y/ `
, z, i  ~+ `9 G3 ]- O2 xeta1=10;  % [Pa.s], l# G6 {$ |' o, ]: e& Z5 G
eta2=20;  % Pa.s]2 \& e2 l1 G, o$ |6 \7 r" y
G1=2;   % [Pa]( w& e' a+ K8 g0 {4 L0 L* p
G2=5;   %[Pa]2 }$ ^5 W5 ]7 ]) ]- v
yieldstress=5;  % [Pa]
: ?2 r1 |5 X( P7 ?3 p$ W0 scontactstrain=5;
4 h, L$ y' H; r6 }5 n, J8 Z! _9 e1 Y$ u& W& Y& x4 i" m
& B% r4 a& A. o$ j. P- V
flow='creep & recovery';
; m# s/ v) j& M& |# c5 x' dstress0=1:2:10;
5 q; ^: ]9 c7 l, K* J6 prisetime=0.01;' a: H. D" h  J0 e( [
creeptime=100;; |( z/ k: F2 z4 z
for i=1:length(stress0)
) {6 j* R1 x1 l    [t,strain]=ode15s(@mywork,[0 10],[0 0],[],eta1,eta2,G1,yieldstress,contactstrain,flow,[stress0(i) risetime creeptime]);1 @- f" d) g% S; }$ ]6 ]
    subplot(2,3,3);     semilogx(t,strain(:,1));        hold on* T9 E) C: Y. D# `8 j6 G& N, a* r9 h
    a{i}=strcatnum2str(stress0(i),'(Pa)');% \$ l* Z$ j0 n8 Z; o% S& @
end
4 I+ |) Z3 U/ t" vxlin([1e-4 1000]);   
( `5 _6 G5 f7 pxlabel('Time(s)');      ylabel('Shear strain(-)');
" Z& t( k' G' t7 u$ {' V7 f# Q' wlegend(a)
, w; E. F& x( S7 l' K
- l( }$ c+ u9 H7 r2 C
* Y' N2 m: R1 f: ?. I
3 x( S4 U" M! L错误使用 odearguments (第 93 行)2 O( \8 j7 m8 W6 D; K) q: ^! {/ |
MYWORK 必须返回列向量。
# g3 u0 H; c# x/ i- p# s+ L! E2 i5 O0 y3 ^
出错 ode15s (第 152 行)( P( E, p( L7 ]( ]
    odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
. }5 b& E$ Q, ^$ h1 \  B1 U) Z6 `3 q: o$ r
出错 Untitled2 (第 20 行)5 j2 }2 d1 s9 N( K+ P7 K
    [t,strain]=ode15s(@mywork,[0 10],[1 0],[],eta1,eta2,G1,yieldstress,contactstrain,flow,[stress0(i) risetime creeptime]);) Y: e3 k& K' g8 c4 D
8 b3 X' c5 E9 w2 k* R* a

! a' L( ~' i- R感谢大神们!
  ^7 n5 z8 ^% r8 K! W- x0 \0 m9 W

该用户从未签到

2#
发表于 2021-1-5 13:09 | 只看该作者
clear all
* a. w/ y% R2 v( }: Kclc
3 t" o7 [  d- ~# j, }4 z% Uwarning off" O! D, V4 }" H  c% W' x' n* Z

& g# ?3 B+ A: b, c4 p* x! Neta1=10;  % [Pa.s]1 }6 R7 U6 C$ z# a
eta2=20;  % Pa.s]
1 M0 \& o; J- l4 v. [/ G9 AG1=2;   % [Pa]
9 s/ O" _! B' J6 g' qG2=5;   %[Pa]
* @' q7 Q6 O1 b5 e+ n# _2 \3 [yieldstress=5;  % [Pa]
# O7 ^9 R- R" v# r, m6 acontactstrain=5;4 _- D& z+ b4 u( q( Y

' [) f# ?' [7 n# l2 A7 `. K$ \/ o6 `% L1 Z  a; V/ D+ i* w
flow='creep & recovery';
- W( e3 `6 w+ n  Y+ X7 i) d1 Kstress0=1:2:10;, c, S" u6 }* M- K* W6 Q  U
risetime=0.01;
) {% q# y! w) K% S$ `/ fcreeptime=100;
7 p5 C& u4 r% Hfor i=1:length(stress0)
( {% i% O7 E% [    [t,strain]=ode15s(@mywork,[0 10],[0 0],[],eta1,eta2,G1,yieldstress,contactstrain,flow,[stress0(i) risetime creeptime]);, C% j' v: t* K9 [$ Q! p! v: s
    subplot(2,3,3);     semilogx(t,strain(:,1));        hold on8 k- u& j- t( N" {
    a{i}=strcat(num2str(stress0(i)),'(Pa)');
+ y# C9 l7 ?5 m7 Y$ y2 hend
! v- b$ X. |7 O; q: i5 |xlim([1e-4 1000]);
  e* k; F7 i/ b2 v( Axlabel('Time(s)');      ylabel('Shear strain(-)');! Q# }' d/ |) {! g
legend(a)6 y0 y- f" ]; @7 }$ P; v
function s=mywork(t,y,eta1,eta2,G1,yieldstress,contactstrain,flow,arg)' ?2 g% ]2 ^3 u' a- x7 u' a
switch flow+ v0 }6 F% y5 H) R' Y8 q9 a
    case 'creep & recovery'& O5 ~3 R! [( L$ u+ T
        stress0=arg(1);6 v2 S" G/ b$ h. ?8 c8 _/ O
        risetime=arg(2);
% {, V# m# r+ S1 {        creeptime=arg(3);
( L: A* }) w* u, d; I        if t<risetime
1 K) P: j8 b$ S' @) \+ W            stressrate=stress0/risetime;
2 \2 a* V; ?; e            stress=stressrate*t;  Q* |- d* ?; n. w
        elseif t<creeptime0 S8 @, w; J$ K; S# D  ^! J
            stressrate=0;
" M- p% R# h0 p9 e# B            stress=stress0;" ^% H' t3 f1 I; }
        elseif t<creeptime+risetime: K$ h8 B8 _' f7 V) A* M0 Q% |
            stressrate=stress0/risetime;8 E8 d& N  f4 f9 H2 {2 K
            stress=stress0-stressrate*(t-creeptime);
, |  E) _+ C* s4 G4 R) r4 E        else
, ]1 O! @0 O6 I1 L5 g            stressrate=0;$ S" f: S. q  S2 i: ^
            stress=0;
0 w! z: c; Q/ Q, _: ~6 u! r        end
0 O# C5 \) |% S( X9 i# O" `) ^5 v        gam1=y(1);' p6 z, ?& Q  s: u# s6 I
        gam2=y(2);. F- _1 T8 h7 T" e
        s(1)=gam2;& \/ O3 o: I/ ^( t6 |/ ]
        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);% I* t, J" ?  w$ l! o
        s=s';9 n1 \& n1 Z/ x5 R; x# E7 }
end1 X- T+ f# d4 n8 _" O+ i! c
end

该用户从未签到

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

本版积分规则

关闭

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

EDA365公众号

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

GMT+8, 2025-10-6 07:25 , Processed in 0.125000 second(s), 23 queries , Gzip On.

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

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

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