From: Sean on
"mistersink sink" <zpsink(a)gmail.com> wrote in message <hs9ijp$6mc$1(a)fred.mathworks.com>...
> "Sean " <sean.dewolski(a)nospamplease.umit.maine.edu> wrote in message <hs995l$d7j$1(a)fred.mathworks.com>...
> > "mistersink sink" <zpsink(a)gmail.com> wrote in message <hs981l$s0r$1(a)fred.mathworks.com>...
> > >
> > > > Create a function file with your function, pass it as a function handle and make an initial guess 0.4144 or 0.2020.
> > >
> > > I'm sorry, I don't understand. how do you create a function file and pass it as a function handle?
> >
> > Here:
> > %%%%%new .m file
> > <top line of file> function [y] = myfunction(x);
> > %x is your variable
> > %y is the value
> >
> > Vl=12.092904976150820;
> > e=[0.058277693076074 0.085256559560097 0.128585397653194];
> > Ve=[2.599650000000001 4.159440000000000 4.159440000000000];
> > summ2=Ve(1)*log(e(1)-e(1)/(1-x*Ve(1)))+Ve(2)*log(e(2)-e(2)/(1-x*Ve(2)))+Ve(3)*log(e(3)-e(3)/(1-x*Ve(3)));
> >
> > y=real(summ2)+Vl;
> > % I think I changed it correctly though no guarantee I ran it and it worked
> > %%%%%%%%
> >
> > >>fzero(@myfunction, .4)
> > ans = 0.414394760826850
> > >>fzero(@myfunction, .1)
> > ans = 0.202001240136841
> >
> >
> > Make sure to use:
> > >> format long
> > to visualize it so you can see the full floating point value.
>
> Thanks for the reply.
> I tried this, but it told me that "??? Input argument "x" is undefined." for the summ2 line.
> also do i make this in another .m file and run it first? i'm not too sure about how functions work and calling them. when i placed the code in the long version of my code, it said "Function definitions are not permitted in this context."


Of course it did, you have to give the function a variable in order for it to work.

You need to:
1) Open a standalone mfile and copy in the function just I showed above.
the top line should be function... and 'function' should be blue otherwise there's an error.
2) In order to run this function you need to do something such as this
>>myfunction(3) % Your result function with variable=3;
Then from somewhere else; your other script, or command window, you can call fzero as I did above.
If you just say >>myfunction; it's not receiving an 'x' and thus throwing the error.
You also can't have functions in scripts, the other error you're seeing.

For a better explanation and examples with functions:
>> doc function
>> doc function_handle
From: mistersink sink on
"Sean " <sean.dewolski(a)nospamplease.umit.maine.edu> wrote in message <hs9jum$4qd$1(a)fred.mathworks.com>...
> "mistersink sink" <zpsink(a)gmail.com> wrote in message <hs9ijp$6mc$1(a)fred.mathworks.com>...
> > "Sean " <sean.dewolski(a)nospamplease.umit.maine.edu> wrote in message <hs995l$d7j$1(a)fred.mathworks.com>...
> > > "mistersink sink" <zpsink(a)gmail.com> wrote in message <hs981l$s0r$1(a)fred.mathworks.com>...
> > > >
> > > > > Create a function file with your function, pass it as a function handle and make an initial guess 0.4144 or 0.2020.
> > > >
> > > > I'm sorry, I don't understand. how do you create a function file and pass it as a function handle?
> > >
> > > Here:
> > > %%%%%new .m file
> > > <top line of file> function [y] = myfunction(x);
> > > %x is your variable
> > > %y is the value
> > >
> > > Vl=12.092904976150820;
> > > e=[0.058277693076074 0.085256559560097 0.128585397653194];
> > > Ve=[2.599650000000001 4.159440000000000 4.159440000000000];
> > > summ2=Ve(1)*log(e(1)-e(1)/(1-x*Ve(1)))+Ve(2)*log(e(2)-e(2)/(1-x*Ve(2)))+Ve(3)*log(e(3)-e(3)/(1-x*Ve(3)));
> > >
> > > y=real(summ2)+Vl;
> > > % I think I changed it correctly though no guarantee I ran it and it worked
> > > %%%%%%%%
> > >
> > > >>fzero(@myfunction, .4)
> > > ans = 0.414394760826850
> > > >>fzero(@myfunction, .1)
> > > ans = 0.202001240136841
> > >
> > >
> > > Make sure to use:
> > > >> format long
> > > to visualize it so you can see the full floating point value.
> >
> > Thanks for the reply.
> > I tried this, but it told me that "??? Input argument "x" is undefined." for the summ2 line.
> > also do i make this in another .m file and run it first? i'm not too sure about how functions work and calling them. when i placed the code in the long version of my code, it said "Function definitions are not permitted in this context."
>
>
> Of course it did, you have to give the function a variable in order for it to work.
>
> You need to:
> 1) Open a standalone mfile and copy in the function just I showed above.
> the top line should be function... and 'function' should be blue otherwise there's an error.
> 2) In order to run this function you need to do something such as this
> >>myfunction(3) % Your result function with variable=3;
> Then from somewhere else; your other script, or command window, you can call fzero as I did above.
> If you just say >>myfunction; it's not receiving an 'x' and thus throwing the error.
> You also can't have functions in scripts, the other error you're seeing.
>
> For a better explanation and examples with functions:
> >> doc function
> >> doc function_handle

thanks that worked. now is there any way to point the cursor on a plot to a certain value of x or y? i can get it close if i drag it, but i want to be more precise.
First  |  Prev  | 
Pages: 1 2
Prev: mcc and own icon
Next: replacing elements of a matrix