필터 지우기
필터 지우기

How to convert symbolic piecewise expression into a function handle

조회 수: 5 (최근 30일)
Vishal  Tripathi
Vishal Tripathi 2016년 3월 6일
댓글: Walter Roberson 2016년 4월 6일
I require to convert a symbolic piecewise expression to a function handle in matlab.
I tried using matlabFunction() but it throws a symengine error of unbalanced or unexpected parenthesis or bracket.
Any help will be highly appreciated.
  댓글 수: 6
Walter Roberson
Walter Roberson 2016년 3월 26일
편집: Walter Roberson 2016년 3월 26일
There is no piecewise if you add the assumption that T >= 300
I recommend you use a different name for the upper bound, such as
syms Tmax
assume(Tmax>300)
fun = int(exp(-E/(8.314*T)),T,300,Tmax);
Now by the time you get to error1, you have a function in which both z and v are free variables. Is it correct that you are trying to minimize over both variables simultaneously?
Vishal  Tripathi
Vishal Tripathi 2016년 3월 26일
편집: Vishal Tripathi 2016년 3월 26일
I think the integration yields a piecewise function because of E or v, and not because of T. However I think I may have found a solution to my problem. [by specifying a bracket for v, so that no piecewise function is formed]
And yes, I'm trying to minimize over both variables simultaneously.
Sadly another problem, which has popped in is that while using fminsearch the function considers E as an undefined function/variable, whereas I have clearly indicated in fun2 that the integration is over the variable E, with limits containing v. (so E should not even exist in the final error function)
Is there a problem with fminsearch, or am I doing some mistake somewhere ?
P.S - I have edited the code above for your reference.

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

답변 (1개)

Walter Roberson
Walter Roberson 2016년 3월 27일
If you write it out with the final integration step not done, and you expand() the terms and combine exponents and simplify, you can show that the minimum must occur when z is the mean of the alphaexp.
Near v = 0 and E = 18000, the integrals are very steep. The key point is near v = 0.002486920643673647643722704 where just a hair less gets you an integral that is so large that it effectively cannot be computed, but a hair more gets you an integral that is amazingly small -- for example values on the order of 1/10^(10^13). I think it means that the minimum is going to be at your upper bound, v < 6000 but the difference between that and any v > 0.002486920643673647643722704 would need to be computed to billions of digits to determine the difference. The inherent inaccuracy in your constants such as 8.314 do not justify those kinds of computations.
  댓글 수: 4
Vishal  Tripathi
Vishal Tripathi 2016년 4월 6일
I understand what you are trying to say. However, what I cannot understand is that if I put the values of v1, v2 and v3, the integration is happening, and I am getting smooth results. Same is the case if I use for numerical integration (using vpa and defining v1, v2 and v3 specifically). Instead when I use fminsearch to optimise for same values, the variable 'E' is being treated as an alien function/variable which it should not according to me. This is what I am unable to grasp and need help for.
I am very sorry for being so ignorant, but since I am very new to MATLAB I request a bit of patience.
P.S - Kindly refer to the above code for computation.
Walter Roberson
Walter Roberson 2016년 4월 6일
Please do not name a variable "error" as that interferes with using the critical MATLAB function error() and makes it difficult for other people to read the code.
Please show the output of error1 and also the output of the matlabFunction call.
I have a vague memory that there might be a bug in the conversion of int() to function handle.

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

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by