Plotting a function over an interval

I am trying to plot a function in which one term is (2^(-1/a))*(1+x)^(1+1/a). When a is very small, for example a=10^-4 or even smaller, this term turns to NaN. How can I plot this function?

댓글 수: 9

Torsten
Torsten 2018년 8월 17일
The best you can do is write your function as
(1+x).*((1+x)/2).^(1/a)
If the problem remains, (1+x)/2 is simply too large (or "a" is too small).
Best wishes
Torsten.
Ali Baig
Ali Baig 2018년 8월 17일
Thank you. It works up to a=10^-6.
Pieter Hamming
Pieter Hamming 2018년 8월 17일
Can you give a little more information about the goal of the plot? This sounds like an occasion where a (semi-)log plot would be suitable. This in turn could help in rewriting the equation
Ali Baig
Ali Baig 2018년 8월 17일
@Pieter hamming, this is exact solution of a convection-diffusion equation. I calculated the numerical solution using Finite Element Method and the goal of the plot was to compare the two solutions.
Pieter Hamming
Pieter Hamming 2018년 8월 17일
I was a bit unclear in my question, sorry. What I meant is more info about the variables involved: size, scale and such.
Is a a single value of 10^-6? Is it a set of points on an interval? If so, how many points and on what interval?
Assuming you want to plot (2^(-1/a))*(1+x)^(1+1/a) for one value of a and a range of x, what range of x do you need?
What do you want with the plot? Visually compare to a previous plot? In that case a log plot should suffice.
These kind of details help a lot in determining how we can help you best. In the future, consider adding them immediately to the question :)
Ali Baig
Ali Baig 2018년 8월 17일
I plotted 6 different graphs. For each graph, ''a'' is constant, and its values are 10^-1, 10^-2,.., 10^-6. Variable ''x'' vary from 0 to 1, and 40 uniformly-spaced x values are used. And the purpose of the graphs is to visually compare the exact solution and the finite element solution.
Thank you for your suggestions.
Torsten
Torsten 2018년 8월 17일
If x only varies from 0 to 1, you should be able to plot your graphs for whatever "a" you want with my suggestion.
Ali Baig
Ali Baig 2018년 8월 17일
I am trying to plot for ''a'' up to 10^-6 and the simplification propsed by Hamming works up to this value.
Torsten
Torsten 2018년 8월 17일
편집: Torsten 2018년 8월 17일
x=linspace(0,1,40);
a=1e-12;
y=(1+x).*((1+x)/2).^(1/a);
plot(x,y)
works for me.

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

태그

질문:

2018년 8월 17일

편집:

2018년 8월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by