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

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

[复制链接]

该用户从未签到

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

EDA365欢迎您登录!

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

x
我的代码解常微分一直说要返回列向量,有大神帮忙看看嘛
/ y/ g8 Q+ \& s' ~! R
6 d2 z$ F2 k# _  t2 a/ k) s这是代码:* }' S* H0 c: L& M2 y& N
function s=mywork(t,y,eta1,eta2,G1,yieldstress,contactstrain,flow,arg); q3 Y4 U; a0 A5 r
switch flow4 Q  L! R" b1 F8 l4 f
case 'creep & recovery'
, k' W% ^! {0 m: B: d  s# S( ?        stress0=arg(1);& X- P2 E% W. C3 V! i2 S
        risetime=arg(2);
* @/ `- F' x! p+ A; d/ Y3 e% X        creeptime=arg(3);2 o, t+ U5 t% a% ?% ?# Q- T% y5 b
        if t<risetime
- Q% D  N$ U& ]$ q9 P            stressrate=stress0/risetime;% J1 ?6 H& J/ Y# ^/ A
            stress=stressrate*t;6 z  p7 K$ G& g4 y( g5 W
        elseif t<creeptime
0 D' A  V8 R2 z            stressrate=0;
" H4 Z2 Y) U  I$ U            stress=stress0;( B2 z, Y* P' d, j6 a' {/ H$ E0 _8 h  a
        elseif t<creeptime+risetime
3 b5 p2 L$ O3 ?9 `! [4 l+ J# z            stressrate=stress0/risetime;9 {: Y! A" j& e* A  t/ Z
            stress=stress0-stressrate*(t-creeptime);9 _1 s4 V' X* e$ z2 p! o- T7 M
        else
: w2 g' M/ i% T& t- O6 ^$ E# @            stressrate=0;- T+ H; B  D6 b9 S1 @9 e, |
            stress=0;$ y7 Z# x) l6 c) n; w4 C
        end3 g9 B/ V* P9 K' O5 G! ?3 b5 F
        gam1=y(1);
& D. J- b. M$ ?+ l2 \& b9 ]- p        gam2=y(2);, Z! C: ]: \5 }- d, A6 K- C/ i
        s(1)=gam2;  V4 A& q" {& C, O5 h1 b6 q* L
        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);
1 r! w+ p& d% p$ |
% U, o9 ~. _5 T( t# j6 D; ^2 d  u" _3 f* T0 S4 S( H- p$ Q, Y

2 E+ g9 h$ x4 D; _$ oclear all
( z4 E! `# L$ C2 T% [1 Pclc/ y: Z/ w- n# {5 N
warning off
; y9 X9 H0 i1 z" @2 M) O- k
/ v/ e. Y# P1 O( |* ~8 Beta1=10;  % [Pa.s]
+ X/ {. s1 k+ r) P4 d$ E' K3 feta2=20;  % Pa.s]
- i% W" c6 `+ k- ^1 Q  m5 SG1=2;   % [Pa]
8 B2 s& |9 H: D" T( K+ nG2=5;   %[Pa]0 F# Y, f9 E" `" _8 J5 X( c
yieldstress=5;  % [Pa]
; n9 b: m5 K% I$ J' @* Zcontactstrain=5;( l! }3 L" C4 ?$ x5 X+ v$ f
6 q) V8 c6 u. d5 x" k# @

4 v$ w# t% U$ E6 t9 Jflow='creep & recovery';2 x) S. k0 W6 C" x4 [
stress0=1:2:10;
6 v; C9 C+ C+ xrisetime=0.01;. S, u! s3 h0 n- P
creeptime=100;4 X, n0 ^) s1 v. X7 A
for i=1:length(stress0)- x. \! O: |9 _. E& W
    [t,strain]=ode15s(@mywork,[0 10],[0 0],[],eta1,eta2,G1,yieldstress,contactstrain,flow,[stress0(i) risetime creeptime]);
$ D& w, \! `5 ^- o+ m: I' l9 s! G    subplot(2,3,3);     semilogx(t,strain(:,1));        hold on$ s6 N4 a3 R& N7 t9 [
    a{i}=strcatnum2str(stress0(i),'(Pa)');
* C$ L) L1 H+ K+ eend; M: E' K; w  G0 v% E8 b  q: i
xlin([1e-4 1000]);   6 v! H' i8 d7 S" d( l
xlabel('Time(s)');      ylabel('Shear strain(-)');, Q% f5 v4 K" q. i7 P1 m
legend(a)' r+ t' [! h. W6 o
# ]& f4 Q  m0 O: r0 C% F

: ^) l6 p0 E0 o$ }
& l9 U8 Q2 t0 y/ u# r错误使用 odearguments (第 93 行)
4 v+ V4 I3 F8 u: B5 \MYWORK 必须返回列向量。$ i5 F0 D$ m& k7 n9 j$ P

3 r& b' o. H3 V/ g9 l- v6 Y出错 ode15s (第 152 行)  M2 }  E9 ^3 q% y8 D& W
    odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
( p$ _1 {/ {2 T1 _) U8 s: h* Z: O) ^) h1 j4 f" Q6 D  l! V
出错 Untitled2 (第 20 行)( f7 z7 z6 a% t
    [t,strain]=ode15s(@mywork,[0 10],[1 0],[],eta1,eta2,G1,yieldstress,contactstrain,flow,[stress0(i) risetime creeptime]);
; {9 e5 y3 K6 }  w. a2 Y+ b+ H7 m+ b. N

; J# v* ?6 h+ @! d6 l; Y感谢大神们!
5 Y: l8 Z1 w) |( W+ D1 C

该用户从未签到

4#
发表于 2021-1-5 15:43 | 只看该作者
来学习一下

该用户从未签到

2#
发表于 2021-1-5 13:09 | 只看该作者
clear all# ?4 Q' Q8 k3 t7 O; P, K4 z- C* f; z
clc7 I" U& v$ Z' ~: w8 e6 L
warning off
) [" v& M( Y, v' F5 C' L. v
9 `7 Q9 E* a3 @8 `  y# reta1=10;  % [Pa.s]
* X! E+ Y& w- n6 H3 F. i: Keta2=20;  % Pa.s]. c! A) R6 l) b' k8 z2 O2 _
G1=2;   % [Pa]1 r  W' y+ _  \6 z4 b
G2=5;   %[Pa]
  F  Y- f3 m  B0 D; S3 _yieldstress=5;  % [Pa]
' c6 C5 `# T9 J$ H) c7 W5 m5 U; X3 Econtactstrain=5;9 h8 b0 n: r* F. M' G7 ^* T7 E

8 w4 G6 ?+ m) ^/ C8 y
/ ?+ D! n9 ~- M( c! Rflow='creep & recovery';
% j5 w) l  {7 Y0 F% Sstress0=1:2:10;
. S8 D- I8 a, G* H1 V& r' [risetime=0.01;
. d$ j; D- v/ w* [9 {creeptime=100;+ ^# s3 _. K: z" v# J6 ]
for i=1:length(stress0)+ m# B) @/ s1 f
    [t,strain]=ode15s(@mywork,[0 10],[0 0],[],eta1,eta2,G1,yieldstress,contactstrain,flow,[stress0(i) risetime creeptime]);
" F. `8 Y% Y1 v1 ?    subplot(2,3,3);     semilogx(t,strain(:,1));        hold on2 ^5 p' }' m  y* M/ j  G& `$ U* y
    a{i}=strcat(num2str(stress0(i)),'(Pa)');
' {; W6 a% u. C5 C& i8 J' dend( j/ [5 w+ N8 x/ B- \9 D
xlim([1e-4 1000]);' n: B3 K/ e. S( [% J' Y. \
xlabel('Time(s)');      ylabel('Shear strain(-)');6 k3 n0 d- D# {( k$ S. |; z
legend(a)
( Y! e- H' u6 A# Kfunction s=mywork(t,y,eta1,eta2,G1,yieldstress,contactstrain,flow,arg)
: _7 w  S) G/ e. {) q/ Lswitch flow$ X6 \4 e. g2 b( l. |
    case 'creep & recovery'/ w: t# J6 r& g
        stress0=arg(1);
/ F/ T% I% t1 s; f* X9 e" N" R0 `        risetime=arg(2);
0 |0 G2 T( t6 _2 L, V. c0 ?/ v! Y5 I. z        creeptime=arg(3);
" T* Y' x* u# ~$ o        if t<risetime
1 h( }# g- I+ i            stressrate=stress0/risetime;. [3 F6 C1 o. s9 `% H4 I$ U: ~
            stress=stressrate*t;( c) y2 X) o& M* E5 l" R( ?
        elseif t<creeptime
) h" m. t! N2 }            stressrate=0;
& T$ h6 Q9 L. A+ l7 B: _- b0 h            stress=stress0;1 p3 l, E# T( `% `/ w
        elseif t<creeptime+risetime
3 y% E9 i# h; @: X. z7 y            stressrate=stress0/risetime;  R/ G0 [: U; [: r% I* N( `
            stress=stress0-stressrate*(t-creeptime);& [" l: U5 ]2 G" K- l- u4 k
        else& U9 N7 f) |; H9 g# k7 _+ h' G+ y8 _
            stressrate=0;- D* s* G2 p/ L# J& O
            stress=0;7 h% q; L( t+ v" ~0 ~7 _4 m. a
        end
2 r1 L( b5 Q/ f: k1 e1 r- m3 X" q: G        gam1=y(1);7 P* a5 ^; s7 G# {2 m9 E, [! F+ W
        gam2=y(2);0 F3 p/ P3 N' }- f9 ?
        s(1)=gam2;7 J+ E! ]# x# F- j  C  L% ?
        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);
, T$ Y7 J7 }. J8 m; f3 d        s=s';+ g; D( E& S  h
end/ `. t: X/ R. o6 S
end
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

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

EDA365公众号

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

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

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

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

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