need help in this

조회 수: 1 (최근 30일)
Ali Najem
Ali Najem 2020년 3월 29일
댓글: Ameer Hamza 2020년 4월 1일
Hello everybody
i just have this code:
syms w1 w2 w3 w4 v1 v2 x1 x2 yd
n1=w1*x1+w2*x2;
o1=1/(1+exp(-n1));
o1_der=o1*(1-o1);
%%
n2=w3*x1+w4*x2;
o2=1/(1+exp(-n2));
o2_der=o2*(1-o2);
%%
n3=v1*o1+v2*o2;
o3=(1/(1+exp(-n3)));
o3_der=o3*(1-o3);
e1=(o3-yd);
%%
A1=((o1^2+o2^2)*o3_der^2 +(x1^2+x2^2)*(v1^2)*o1_der^2*o3_der^2+(x1^2+x2^2)*(v2^2)*(o2_der^2)*o3_der^2);
%%
aa=e1*A1;
aw1=diff(aa,w1);
I need to take (aw1) which is derived (aa) respect to (w1) then use it in b.m file for example.. (aw1 is symbolic i mean all values inside are varibals).
The error below occure when i save aw1 as a data and load it in another file and run
(Inputs must be floats, namely single or double.
Error in ode15s (line 150)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in simple (line 44)
[T1,cox]=ode15s(@(t,y1) Costatesimple(t,y1,u,x1,x2,yd,x1t,e1,w1,w2,w3,w4,v1,v2),tspan2,[0 0 0 0 0 0 0],options);
any help please?
however, it works when i copy all values insied aw1 and paste it in b.m file..
due to the value of aw1 is too long so, i need way to move it to another file without copy and paste
i would you to help in this issue please.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 3월 29일
When saving aw1 in a.m you need to save all other symbolic variables too
save('filename.mat', 'aw1', 'w1', 'w2', 'w3', 'w4', 'v1', 'v2', 'x1', 'x2', 'yd' );
and then load the file in b.m
load('filename.mat');
Alternatively, you can also try to just save aw1
save('filename.mat', 'aw1')
and then in b.m write
load('filename.mat');
syms w1 w2 w3 w4 v1 v2 x1 x2 yd
For a bit detailed discussion on this topic, refer to Walter's answer and my comments here: https://www.mathworks.com/matlabcentral/answers/513625-how-to-save-a-symbolic-equation-in-a-txt-file#answer_422592
  댓글 수: 10
Ali Najem
Ali Najem 2020년 4월 1일
thank you so much bro it worked
i appreciate your time to solve my issue
am so grateful to assisted me.
Ameer Hamza
Ameer Hamza 2020년 4월 1일
Glad to be of help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by