86

edits

Jump to navigation
Jump to search

copy edit for demo

(→Demos and usage examples: rework the evaluate-at-double example) |
(copy edit for demo) |
||

Line 5: | Line 5: | ||

=== Demos and usage examples === | === Demos and usage examples === | ||

* ''' I'm trying to substitute a double value into an expression. How can I avoid getting "warning: Using rat() heuristics for double-precision input (is this what you wanted?)" | * '''I'm trying to substitute a double value into an expression. How can I avoid getting "warning: Using rat() heuristics for double-precision input (is this what you wanted?)".''' | ||

In general, you should be very careful when converting floating point ("doubles") to symbolic variables, that's why the warning is bothering you. | In general, you should be very careful when converting floating point ("doubles") to symbolic variables, that's why the warning is bothering you. | ||

Line 45: | Line 45: | ||

% have fun and change it if you want to. | % have fun and change it if you want to. | ||

f=@(x) x.^2 +3*x-1 + 5*x.*sin(x); | f = @(x) x.^2 + 3*x - 1 + 5*x.*sin(x); | ||

% | % these next lines take the Anonymous function into a symbolic formula | ||

pkg load symbolic | |||

syms x; | syms x; | ||

ff = f(x); | |||

ff= | |||

% now calculate the derivative of the function | % now calculate the derivative of the function | ||

ffd=diff(ff); | ffd = diff(ff, x); | ||

% and convert it back to an Anonymous function | % and convert it back to an Anonymous function | ||

df=function_handle(ffd) | df = function_handle(ffd) | ||

% this uses the interval pkg | % this uses the interval pkg to find all the roots between -15 an 10 | ||

pkg load interval | |||

fzero (f, infsup (-15, 10), df) | fzero (f, infsup (-15, 10), df) | ||

86

edits

Retrieved from "https://wiki.octave.org/Special:MobileDiff/9876"