I need help with Matlab
Show older comments


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.
Answers (2)
Star Strider
on 10 Feb 2019
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 Comments
Patrick Potts
on 10 Feb 2019
Edited: Patrick Potts
on 10 Feb 2019
Star Strider
on 10 Feb 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
on 10 Feb 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
on 10 Feb 2019
Star Strider
on 11 Feb 2019
If my Answer helped you solve your problem, pleae Accept it!
Walter Roberson
on 10 Feb 2019
0 votes
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 Comments
Patrick Potts
on 10 Feb 2019
Walter Roberson
on 10 Feb 2019
x0 = SomethingThatYouWillHaveToFigureOut
fsolve(@fun1, x0)
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!