solving trascendental equations, proper setting
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hello everybody,
I'd like to solve for y = y(x) the following equation
d log( y ) / d x + y = 1 + f
with f = f(x).
f is a 1D numerically known array, I don't know its nalytical form.
I cannot set properly solve or fzero.
Can you help me, please?
Patrizio
채택된 답변
Ameer Hamza
2020년 6월 14일
편집: Ameer Hamza
2020년 6월 14일
This is a differential equation and you can use symbolic toolbox to find an anayltical solution
syms y(x) f
eq = diff(log(y), x) + y == 1 + f;
sol = dsolve(eq);
Result
>> sol
sol =
(exp((C1 + x)*(f + 1))*(f + 1))/(exp((C1 + x)*(f + 1)) + 1)
f + 1
Following shows how to get a numerical solution using ode45
syms y(x) f
eq = diff(log(y), x) + y == 1 + f;
sol = dsolve(eq);
odeFun = matlabFunction(odeToVectorField(eq), 'Vars', {'t', 'Y', 'f'});
tspan = [0 10]; % time span for numerical solution
ic = 1; % initial condition: y(0)==1
fv = 1; % numerical solution for f=1
[t, y] = ode45(@(t, y) odeFun(t, y, fv), tspan, ic);
plot(t, y);
댓글 수: 7
PatrizioGraziosi
2020년 6월 14일
편집: PatrizioGraziosi
2020년 6월 14일
Thank you Ameer!
In the system I'm stuying, for each 'x' value there is one value for 'f' and one value for 'y'.
I mean, there is a f(x) that I know and a y(x) I don't know but for each 'x' value there are only one 'f' and one 'y' . I know f(x) and the relation between f(x) and y(x), and should find y(x).
As far as I understand, the tspan plays the role of the 'x' variable and I get a y(x) for each 'fv' but this not actually the case: for each 'x' value I have also a different 'fv' value.
Hope this makes my problem clearer. If I have misunderstood your answer, sorry.
About the symbolic toolbok lines you wrote, it looks to be the case for a scalar f.
if I input
syms y(x) f(x)
I get this
sol =
exp(int(f(x) + 1, x, 'IgnoreSpecialCases', true, 'IgnoreAnalyticConstraints', true))/(C6 - int(-exp(int(f(x) + 1, x, 'IgnoreSpecialCases', true, 'IgnoreAnalyticConstraints', true)), x, 'IgnoreSpecialCases', true, 'IgnoreAnalyticConstraints', true))
that I don't understand clearly. I wonder if you can hel me again, please.
Thanks
Patrizio
I get your point. Yes, tspan plays the role of 'x'. Even if f is a function of 'x', you can consider that in the above code, f(x)=1, i.e., it is a constant function. Although, I agree with your point that in the general case, f and y need to vary with 'x'. Do you have a specific expression for f(x)? Solving it using dsolve() for general case f(x) might not give any useful results.
Hi Ameer, thanks!
Unfortunately f(x) is an experimental measurements and I don't have a precise analytical expression for it. I would need of y(x) to fit it and disentangle between two physical possibilities...
Anyway, I'l keep thinking about.
Ameer Hamza
2020년 6월 14일
편집: Ameer Hamza
2020년 6월 14일
If f is a function of 'x' but obtained experimentally, then you can use the solution in my answer by considering 'f' as a symbolic variable. Following shows how it can be done
syms y(x) f
eq = diff(log(y), x) + y == 1 + f;
sol = dsolve(eq);
odeFun = matlabFunction(odeToVectorField(eq), 'Vars', {'t', 'Y', 'f'});
xspan = 0:0.1:10; % time span for numerical solution
ic = 1; % initial condition: y(0)==1
fv = rand(size(xspan));
ffun = @(x) interp1(xspan, fv, x);
[x, y] = ode45(@(x, y) odeFun(t, y, ffun(x)), xspan, ic);
plot(x, y);
Here I used xspan as a vector, and the values of function f (fv) are also available for the values in xspan. I generated fv randomly in this code.

Thank you so much!!!
It will take to me a few days to test it, I'll keep you posted.
Hi Ameer,
you're solution is brilliant!
Sorry that I couldn't test it before... Your support has been excellent!
In the case we publish the data analysis done thanks to your solution, we'll aknowledge your support.
Thanks
Patrizio
I am glad that it worked for your case, and you got the results. Good luck with your research.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
제품
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
