Problem solving 2 equation 2 unknown

Hi all
I must say to start that it is the first time i am trying to do this on matlab so i started by reading a bit on the subject. I ended up using syms for 2 unknows which in my case are v and et and when i try to use the equations which are :
eq1 = (v*normcdf(1/(et*sqrt(t))*((log(v/M))+(r+(et^2/2)*t)))-(M*exp(-r*t))*normcdf(1/(et*sqrt(t))*((log(v/M))+(r-(et^2/2)*t)))-prix)
eq2 = ((et*(v/prix))*normcdf(1/(et*sqrt(t))*((log(v/M))+(r+(et^2/2)*t))))-sig
and i get this error message :
??? Error using ==> NaN
Trailing string input must be 'single' or 'double'.
Error in ==> normcdf at 62
p = NaN(size(z),class(z));
For now all my others variables are defined as only one value( i just wanted to test the whole thing before looping it) and when i put a value for v and et i get an awnser from each equation so i dont know what is wrong or what i am doing wrong but it is impossible to solve for anything if matlab doesnt accept my equations so i am kind of stucked here some help would be really appreciated
once my equations are gonna be accepted il use [v et] = solve(eq1,eq2) to get my awnsers for v and et but i cant seem to get threww the step before .....
If anyone have any alternative ways to solve these and find my values il be pretty happy to
Sorry for my english my first language is french

댓글 수: 4

Star Strider
Star Strider 2012년 10월 11일
편집: Star Strider 2012년 10월 11일
The normcdf function does not apply to symbolic equations. I suggest you first re-write your equations as:
syms v et t M r prix nmlcdf(z) z sig
nmlcdf(z) = erfc(-z/sqrt(2))/2; % Equivalent to ‘normcdf’
eq1 = (v*nmlcdf(1/(et*sqrt(t))*((log(v/M))+(r+(et^2/2)*t)))-(M*exp(-r*t))*nmlcdf(1/(et*sqrt(t))*((log(v/M))+(r-(et^2/2)*t)))-prix)
eq2 = ((et*(v/prix))*nmlcdf(1/(et*sqrt(t))*((log(v/M))+(r+(et^2/2)*t))))-sig
then solve them.
Walter Roberson
Walter Roberson 2012년 10월 11일
Star Strider, I suggest you make this an answer
Brian
Brian 2012년 10월 15일
Hi thank you for your fast awnser start strider but i still have a problem with the way u told me which seems very logic but still doesnt work. First when i try to use the nmlcdf i have an error telling me that z is an unindentified variable and when i use syms z and try to use the formula u wrote me for nmlcdf i get an error syaing :
nmlcdf(z) = erfc(-z/sqrt(2))/2; ??? Undefined function or method 'erfc' for input arguments of type 'sym'.
So i am still stocked at the same point .... (sorry if i a m bit retarded i might not be the best matlab user in town but i cant get threw here)
Plz help me again and thank you very much
Star Strider
Star Strider 2012년 10월 15일
@Walter Roberson — I did. Thank you.

댓글을 달려면 로그인하십시오.

답변 (1개)

Star Strider
Star Strider 2012년 10월 15일
편집: Star Strider 2012년 10월 15일

0 개 추천

The normcdf function does not apply to symbolic equations. I suggest you first re-write your equations as:
syms v et t M r prix nmlcdf(z) z sig
nmlcdf(z) = erfc(-z/sqrt(2))/2; % Equivalent to ‘normcdf’
eq1 = (v*nmlcdf(1/(et*sqrt(t))*((log(v/M))+(r+(et^2/2)*t)))-(M*exp(-r*t))*nmlcdf(1/(et*sqrt(t))*((log(v/M))+(r-(et^2/2)*t)))-prix)
eq2 = ((et*(v/prix))*nmlcdf(1/(et*sqrt(t))*((log(v/M))+(r+(et^2/2)*t))))-sig
then solve them.
NOTE: I am using 2012b.

댓글 수: 2

Star Strider
Star Strider 2012년 10월 15일
Brian commented:
Hi thank you for your fast awnser start strider but i still have a problem with the way u told me which seems very logic but still doesnt work. First when i try to use the nmlcdf i have an error telling me that z is an unindentified variable and when i use syms z and try to use the formula u wrote me for nmlcdf i get an error syaing :
nmlcdf(z) = erfc(-z/sqrt(2))/2; ??? Undefined function or method 'erfc' for input arguments of type 'sym'.
So i am still stocked at the same point .... (sorry if i a m bit retarded i might not be the best matlab user in town but i cant get threw here)
Plz help me again and thank you very much
I thought erf, erfc, and the rest have been part of MATLAB Symbolic Math Toolbox for a very long time. (I am using 2012b.)
I suggest you try this to see what the result is:
syms t z
qerfc = (2/pi)*int( exp(-t^2), t, z, Inf)
I got this result:
qerfc =
-(5734161139222659*pi^(1/2)*(erf(z) - 1))/18014398509481984
If the Symbolic Math Toolbox is working correctly on your system, you should get something similar. (This is the mathematical definition of erfc. I called it ‘qerfc’ so MATLAB would not confuse it.)
What are you solving for? You might have to simplify your equations as much as possible, convert them to anonymous functions (using matlabFunction in the Symbolic Math Toolbox), and solve them numerically.
I will provide as much help as I can. You are definitely not retarded — we all needed time to learn MATLAB — and I can only wish that my French was as good as your English!

댓글을 달려면 로그인하십시오.

질문:

2012년 10월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by