function [y] = hwk1prob1(x)
hwk1prob1= @(x)[tanh(2*x(1)-3*x(2)^2)+1;
exp(.3*x(1)+.4*x(2))-4.7];
y = fsolve( myhwk1prob1,x)
end
This is the code I have written for solving this problem yet I keep runnig into errors such as not enough input arguments, undefined function. I am really new to matlab so any help would be greatly appreciated.

Respuestas (2)

Star Strider
Star Strider el 10 de Feb. de 2019

0 votos

The problem is that you named your parent function and your anonymous function the same. That’s going to cause problems.
Try this slightly edited version:
function [y] = hwk1prob1(x)
hwk1prob1fcn = @(x)[tanh(2*x(1)-3*x(2)^2)+1;
exp(.3*x(1)+.4*x(2))-4.7];
y = fsolve(hwk1prob1fcn,x);
end
x = [42; 42];
y = hwk1prob1(x) % Function Call

5 comentarios

Patrick Potts
Patrick Potts el 10 de Feb. de 2019
Editada: Patrick Potts el 10 de Feb. de 2019
I tried using your code instead and it still came up with the same issues not enough input arguments, undefined function. So I am at a loss of words since I am just a novice with matlab and it is extremely frustrating to deal with.
Star Strider
Star Strider el 10 de Feb. de 2019
The code I posted ran for me without error. I would not have posted it otherwise.
It produced:
y =
10.5195
-4.0207
Walter Roberson
Walter Roberson el 10 de Feb. de 2019
The two lines at the bottom, x = [42; 42]; y = hwk1prob1(x); should go outside of the hwk1prob1.m file . They are showing how to execute the code.
However... your assignment is to create a hwk1prob1.m that does not expect any input, and which determines its own x value to pass as the second parameter to fsolve()
Patrick Potts
Patrick Potts el 10 de Feb. de 2019
I just wanted to make sure there was nothing wrong with my matlab so the values came out just fine. Thanks for all your help.
Star Strider
Star Strider el 11 de Feb. de 2019
If my Answer helped you solve your problem, pleae Accept it!

Iniciar sesión para comentar.

Walter Roberson
Walter Roberson el 10 de Feb. de 2019

0 votos

You are asked to write a program hwk1prob1.m . It is not asked to be a function . No input will be passed to it.
Your code needs to try several different x values to find one that works.
Numerically, your function has solutions because of round-off error. Mathematically at least one of the two inputs needs to be infinite for there to be a solution. This is partly because the code shown for fun1 does not implement the equation in the description. Look at where the 1 is relative to the tanh() call: in the equation it is inside the tanh() but in the code it is outside the tanh() . This makes a large difference in the meaning of the equation.

2 comentarios

Patrick Potts
Patrick Potts el 10 de Feb. de 2019
If that is the case could you show me how to get started with matlab because I am just a beginner with what you said in mind because I am still confused?
Walter Roberson
Walter Roberson el 10 de Feb. de 2019
x0 = SomethingThatYouWillHaveToFigureOut
fsolve(@fun1, x0)

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 10 de Feb. de 2019

Comentada:

el 11 de Feb. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by