From: mistersink sink on
Hi everyone,
I'm pretty new to Matlab and I need some help.
here is an excerpt of my code:
-----
clear
clc
Vl=12.092904976150820;
e=[0.058277693076074 0.085256559560097 0.128585397653194];
Ve=[2.599650000000001 4.159440000000000 4.159440000000000];
variable=-5:.0005:5;
maxsize=(size(variable));
for i=1:maxsize(1,2)
summ2(i)=Ve(1)*log(e(1)-e(1)/(1-variable(i)*Ve(1)))+Ve(2)*log(e(2)-e(2)/(1-variable(i)*Ve(2)))+Ve(3)*log(e(3)-e(3)/(1-variable(i)*Ve(3)));
end
constraint=real(summ2)+Vl;
plot(variable,constraint)
-----
This basically plots a complicated function of "variable" over a range from -5 to 5.
It creates a plot with two crossings of the x-axis. I've manually found these to be approximately variable=.2020 and variable=.4144.
the value .2020 is no good and i want to find the exact value of the .4144 root.
I will be using this value later on, so is there a way to find this using code?
Also, it would be nice if i could mark these two constraint=0 crossings on the plot. It would be nice if I could put it in the code, but doing it with plot tools would be ok too.

Thanks for your help!
-mistersink
From: Sean on
"mistersink sink" <zpsink(a)gmail.com> wrote in message <hs95b9$spu$1(a)fred.mathworks.com>...
> Hi everyone,
> I'm pretty new to Matlab and I need some help.
> here is an excerpt of my code:
> -----
> clear
> clc
> Vl=12.092904976150820;
> e=[0.058277693076074 0.085256559560097 0.128585397653194];
> Ve=[2.599650000000001 4.159440000000000 4.159440000000000];
> variable=-5:.0005:5;
> maxsize=(size(variable));
> for i=1:maxsize(1,2)
> summ2(i)=Ve(1)*log(e(1)-e(1)/(1-variable(i)*Ve(1)))+Ve(2)*log(e(2)-e(2)/(1-variable(i)*Ve(2)))+Ve(3)*log(e(3)-e(3)/(1-variable(i)*Ve(3)));
> end
> constraint=real(summ2)+Vl;
> plot(variable,constraint)
> -----
> This basically plots a complicated function of "variable" over a range from -5 to 5.
> It creates a plot with two crossings of the x-axis. I've manually found these to be approximately variable=.2020 and variable=.4144.
> the value .2020 is no good and i want to find the exact value of the .4144 root.
> I will be using this value later on, so is there a way to find this using code?
> Also, it would be nice if i could mark these two constraint=0 crossings on the plot. It would be nice if I could put it in the code, but doing it with plot tools would be ok too.
>
> Thanks for your help!
> -mistersink

>>help fzero
Create a function file with your function, pass it as a function handle and make an initial guess 0.4144 or 0.2020.
From: mistersink sink on

> 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?
From: Sean on
"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.
From: mistersink sink on
"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."
 |  Next  |  Last
Pages: 1 2
Prev: mcc and own icon
Next: replacing elements of a matrix