I have a book with some good radar equations in it. However, everything is in Mathcad - I use Matlab. I've been converting everything I use from Mathcad to Matlab. I've run into one I'm not sure how to convert.
Mathcad has a function called root. The equation I'm interested in converting is: root(f1(u) - sqrt(0.5), u, 0.3, 0.7
As I understand it, 'root' returns the value of u to make the function f1 equal to zero. With 0.3 and 0.7 being specified, root finds u on this interval.
How do I accomplish the same thing using Matlab?
Thanks, Kim

댓글 수: 1

SKar
SKar 2021년 3월 30일
Hey Kim,
Is there a way to convert automatically a Mathcad file to a matlab file?
Thank you,
Stratos

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

 채택된 답변

Eric
Eric 2013년 7월 18일
편집: Eric 2013년 7월 18일

2 개 추천

Look at the documentation for Matlab's fzero() function. For example, to find the zero of cosine between 1 and 2:
fun = @cos; % function
x0 = [1 2]; % initial interval
x = fzero(fun,x0)
x is returned with a value of 1.570796326794897.
For your case you'll use something like
fun = @(x)f1(x) - sqrt(0.5);
and of course you'll define x0 to be [0.3 0.7].
Note that the documentation for Matlab R2013a has a typo. In my code above where I defined x0, the documentation actually defines this as x (i.e., they forgot the 0).
Good luck,
Eric

댓글 수: 3

It has taken me forever to get back to this. When I tried your example it worked fine, when I tried mine it didn't. Got the following: >> x0 = [0.3 0.7]; >> fun = @(u)f1(u) - sqrt(0.5); >> x = fzero(fun,x0) Error using fzero (line 233) FZERO cannot continue because user supplied function_handle ==> @(u)f1(u)-sqrt(0.5) failed with the error below.
Undefined function 'f1' for input arguments of type 'double'.
The error is simple: you didn't define a function 'f1' anywhere. Did you create a file called f1.m with your function? What does this:
which f1
give you?
Kim
Kim 2013년 11월 13일
Yep, that was the problem. In my problem f1(u) = sinc(pi*u). So I changed what I did to: fun = @(u) sinc(u) - sqrt(0.5); u0 = [0.3 0.7]; x = fzero(fun,u0)
Note - I had to learn that in mathcad sinc is straight sin(x)/x and for matlab it is sin(pi*x)/(pi*x) - so had to take care of pi.
But now it works.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

태그

질문:

Kim
2013년 7월 18일

댓글:

2021년 3월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by