Simbolic variables with hpf

I am writing a code that needs to evaluate big values of sinh and cosh without giving NaN. I was suggested to use hpf toolbox.
Now I would like to know if it is necessary to use symbolic variables to define all the variables or if it is enough if I put hpf inside THE argoment of sinh and cosh... I am building a series function of X and Y that includes ratios of sinh and cosh and I am currently doing it by the old fashioned for cycles and by defining arrays for x variable and Y variabile in order to get a Matrix of values of my function for each X-Y point. At the end its values in each point should be not extremely big values...
Apart from THE lenght of THE calculation I would like to know it I need to write a new script with symbolic variables or not.

11 Comments

I have Aldo tried to simplify THE expressions in order to avoid the usage of hpf but still have not managed to get acceptable results.
I don't understand. Use one or the other. But, no. You cannot mix HPF with SYM variables. But it is not clear why you think you need to use SYMs. Do you have an UNKNOWN symbolic variable? If so, then you need to use syms. You can have matrices of HPF numbers too.
Orlando Palone
Orlando Palone on 17 May 2020
Edited: Orlando Palone on 17 May 2020
No I was given a script in which both hpf and sym variables where Used and I though there was some kind of correlation.
So, since I have this ratios of sinh and cosh that give me trouble while the rest of the script works with no problem is it sufficient to put hpf in THE arguments of sinh and cosh and nowhere else?
Or is it better if i put hpf at THE beginning of THE problem where i define all THE imputs, ie a = hpf(input value)
It is probably not sufficient to do that. You will probably need to create a small block of code that uses hpf, and you will need to explicitly convert the output values to double() .
It might be feasible to confine all of the hpf work to one function, but I suspect that you will need slightly more change than you outline.
Ok thank you. So to resume I give THE input values as always ie a = 3. Then do all the operations till I arrive to THE point in which I have sinh and cosh. Here I use hpf in THE argument of sinh and cosh. Then I convert THE output values to double and go on ie in this case have a new iteration of THE for cycle. Does it have sense? How do I convert THE values to double?
You should not be switching back to double until after you have calculated the ratio.
Note that for sufficiently large x1, x2, then sinh(x1)/sinh(x2) is exp(x1)/exp(x2) to within any reasonable working precision, which is exp(x1-x2) .
Ok but how do I switch?
double() applied to the hpf object.
Be very careful in converting numbers to double precision, if the exponent is too large, then you will get an overflow. The conversion to double will give you garbage, probably an inf.
A safer way to convert to a sym is
X = cosh(hpf(10000,50))
X =
4.4034091128314607936307480038222805017600020427958e4342
You cannot create a double from that, since it will overflow, since 10^4342 is well outside the dynamic range of a double. X lives in a 50 decimal digit representation. If we are careful, you can pass that into sym to convert it like this:
Y = sym(disp(X))
Y =
4.403409112831460793630748e+4342
vpa(Y,100)
ans =
4.403409112831460793630748003822280501760002042795800000000000000120636373104176091418844252285712053e+4342
class(Y)
ans =
'sym'
So Y is now a sym, that agrees with X to 50 decimal digits. By forcing VPA to go out to 100 digits, we got some extra garbage in there, but that is the fault of the SYM conversion, not due to HPF. The first 50 digits were as desired.
Ok thanks.
I was wondering one thing. Since I am not interested in THE decimal digit representation because in some ways my calculation will give me low values, am i right if i impose a low number of digits in THE hpf in order to increase THE speed of calculation. The important thing is that I do not get a Nan Whenever high arguments appear but this dooesn’t mean that I need a full digit representation.
Yes. You can in theory use a lower number of digits in HPF. I'm not sure if I'd go too short though, as then you might start seeing numerical problems. 15-20 digits is probably a good minimum.
X = hpf(1000000000,[18 2]);
Y = cosh(X)
Y =
4.00149088522032535e434294481
So X lives in 18 digits of precision, with some hidden digits for safe keeping. Does it save some time? A little, but not a huge amount.
X = hpf(1000000000,[50 2]);
timeit(@() cosh(X))
ans =
0.0114933514265
X = hpf(1000000000,[18 2]);
timeit(@() cosh(X))
ans =
0.0096059754265
So, by cutting the number of digits carried from 50 to 20, I managed roughly a 15% decrease in the time consumed for a call to cosh.
Don't try to convert it to a double of course. And you can't even go to a sym with that one. It actually overflows the sym class, resulting in a symbolic inf.
sym(disp(Y))
ans =
RD_INF

Sign in to comment.

Answers (0)

Tags

Asked:

on 17 May 2020

Edited:

on 18 May 2020

Community Treasure Hunt

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

Start Hunting!