how to write exponential equations in matlab

10 views (last 30 days)
I want to write this equation in matlab
and calculate values for this equation buy giving input values for x(1,0)
  4 Comments
Torsten
Torsten on 30 Apr 2023
Edited: Torsten on 30 Apr 2023
You must call the function "grad" with a numerical input for x to get a reasonable output:
g = grad([1 1])
g = 2×1
82.3421 46.1711
function g = grad(x)
g(1,1) = 2+4*x(1)*exp(2*x(1)^2+x(2)^2);
g(2,1) = 6*x(2)+2*x(2)*exp(x(2)^2+2*x(1)^2);
end
Walter Roberson
Walter Roberson on 30 Apr 2023
Edited: Walter Roberson on 30 Apr 2023
syms x [1 2]
g = grad(x)
g = 
solution = solve(g)
Warning: Unable to solve symbolically. Returning a numeric solution using vpasolve.
solution = struct with fields:
x1: -0.37654458248983740789829168140318 x2: 0
fimplicit(g, [-1 1])
function g = grad(x)
g(1,1) = 2+4*x(1)*exp(2*x(1)^2+x(2)^2);
g(2,1) = 6*x(2)+2*x(2)*exp(x(2)^2+2*x(1)^2);
end

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 30 Apr 2023
This works:
x = [0.3, 0.4]; % [x1, x2]
g = MyFunction(x)
g = 1×2
3.6859 3.5240
function g = MyFunction(x)
g(1) = 2+4*x(1)*exp(2*x(1)^2+x(2)^2);
g(2) = 6*x(2)+2*x(2)*exp(x(2)^2+2*x(1)^2);
end

Categories

Find more on Symbolic Math Toolbox 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!