A couple of beginner's questions
Stefan Pofahl
stefan at pofahl.de
Wed Feb 27 00:40:44 CST 2008
Here is my answer, perhaps it helps to handle the function
"fminbnd" for octave beginners, the documentation for the
function is in my opinion only helpful for advanced users.
Regards,
Stefan
############################################################
## question from p.numminen at suomi24.fi
## How would I command Octave in order to find all the values of x that would
## make the functions
##
## f1(x) = 1.035568^x * 1000 - 1000 and
## f2(x) = (1.025668^x * 1000 - 1000) * 0.72
##
## equal with each other?
## --
## My attempt to solve the problem: transform it into a optimization problem:
## y = (f1(x) - f2(x))^2, optimization: y should be zero
function numminen()
x=[-100:20]'; # vector with one column
y1= x; # tell octave the format an size of the array y1
y2= x; # tell octave the format an size of the array y2
for i=1:size(x)(1)
y1(i)=testfunction(x(i));
y2(i)=minimumfunction(x(i));
endfor
## fminbnd is part of octave-forge package
## and searches for the minimum of a function, between a and b:
## http://octave.sourceforge.net/doc/optimization.html
## first approach: a "anonymous function"
anonymtestf = @(x) (1.035568^x * 1000.0 - 1000.0 + ...
(1.025668^x * 1000.0 - 1000.0) * 0.72)^2;
[xatmin,ymin]=fminbnd(anonymtestf, -100, 20)
## second approach, use a named function, here you need the "@"
[xatmin,ymin]=fminbnd(@minimumfunction, -100, 20)
## plotting
clg;
hold on;
plot(x,y1,";testfunction;");
plot(x,y2/max(y1), ";minimumfunction;");
## legend("testfunction", "minimumfunction") #octave 3.0
hold off;
function [y] = testfunction(x)
y= (1.035568^x * 1000.0 - 1000.0 + (1.025668^x * 1000.0 - 1000.0) * 0.72);
endfunction # end testfunction()
function [y] = minimumfunction(x)
y= (1.035568^x * 1000.0 - 1000.0 + (1.025668^x * 1000.0 - 1000.0) * 0.72)^2;
endfunction # end minimumfunction()
endfunction # end numminen
###################################################
2008/2/26, Kamaraju S Kusumanchi <kamaraju at bluebottle.com>:
> p.numminen wrote:
>
> >
> > Question 1:
> > How would I command Octave in order to find all the values of x that would
> > make the functions
> >
> > f1(x) = 1.035568^x * 1000 - 1000 and
> > f2(x) = (1.025668^x * 1000 - 1000) * 0.72
> >
> > equal with each other?
> >
>
>
> If it is just a one time thing, you can just plot the functions using say
> gnuplot, and zoom in on the point of intersection.
>
>
> >
> > Question 2:
> > How would I command Octave in order to solve the equation
> >
> > 1.035568^x * 1000 - 1.025668^x * 720 - 280 = 0
> >
>
>
> Same again. Use gnuplot or other plotting software and zoom in where the
> curve hits x-axis.
>
> raju
>
> --
> Kamaraju S Kusumanchi
> http://www.people.cornell.edu/pages/kk288/
> http://malayamaarutham.blogspot.com/
>
>
> _______________________________________________
> Help-octave mailing list
> Help-octave at octave.org
> https://www.cae.wisc.edu/mailman/listinfo/help-octave
>
--
Tel.: 0731-3805149
Ochsensteige 48
89075 Ulm
More information about the Help-octave
mailing list