I am trying to solve for x in the following equation:
Where I am trying to solve for x but the integral is too big to do by hand.
This is my attempt in MatLab
clc
clear all
close all
syms x t
eqn = (1-(1/(1.3*10^12))*int((t*15)*exp(-t),0,16*x)) == 10^(-4)
sol = solve(eqn,x)
this is the result that I got . The correct number should be approximately 2.2. I am very thankful for your help.
Related
Suppose i have an equation that looks like this: x = y + zx
I have the values for y and z, I want to calculate x. How would I do this on Matlab without having to solve for x on paper?
Probably a simple equation but I am new, thank you!
I tried just writing the equation out and coding disp(x), but of course it did not work.
The function fzero() will give you a numeric answer if you move all of one side of the equation over to the other side, so the first side is equal to zero.
y = 4;
z = 2;
% Move everything to the right side
zero_left_side = #(x)(y+z*x) - (x);
initial_guess = 1;
x_solution = fzero(zero_left_side, initial_guess);
I'm new at matlab programming, and I'm having difficulties with for loop. So my problem is for ex solving this equation Y(x) =1/(x^3-2), x values between some numbers and increasing in a certain amount. The code which I wrote is;
x = 5:0.1:9;
for i = 1:length(x)
y(i) = 1/(i^3-2);
fprintf("%c %c \n",x(i),y(i))
end
However values for Y(x) is wrong. Can anyone explain me this?
I have been trying to solve this question in matlab but i’m having some trouble to solve the question.
Here is the question:
Determine the local minimum, local maximum, and inflection points for the functions
Here is the function
Here is my matlab script
syms [x1,x2]
f = 3*x1.^2+2*x1.*x2+2*x2.^2+7;
G = gradient(f,[x1,x2]);
S = solve(G(1),G(2));
[S.x1 S.x2]
%settting gradient to zero givens x=(0, 0) as the only candidate minimum point
H = hessian(f,[x1,x2])
when I run the script I get this
and it feels like something is wrong
Someone who can help me with this?
You can use the fmincon command for finding the minimum of a function:
clc
clear
close all
x0 = [10 -10];
[x, fval]=fmincon(#myFunc1, x0)
function result = myFunc1(x)
result = 3*x(1)^2+2*x(1)*x(2)+2*x(2)^2+7;
end
Hello I'm trying to integrate the following function in MATLAB
And this is my attempt at evaluating it at a given (x,y)
fun = #(t,x,y) exp(1i.*(t.^4+x.*t.^2+y.*t));
P = #(x,y) integral(#(t)fun(t,x,y),-Inf,Inf);
P(1,1)
According to WolframAlpha the answer is 1.20759 + 0.601534 i for P(1,1)
but MATLAB returns -6.459688464052636e+07 - 8.821747942103466e+07i
I am wondering how to enter an integral like this correctly.
I have now also tried evaluating this symbolically and using a taylor series to approximate but still no luck.
syms x y t
x=1
y=1
f = exp(1i*(t^4+x*t^2+y*t));
fApprox = taylor(f, t, 'ExpansionPoint', 0, 'Order', 10)
sol=int(fApprox,t,[-inf inf])
Any additional suggestions
Many thanks in advance.
I have to find value of x that minimizes norm of C*exp(2x)-d subject to x >= 0. I am trying to solve this problem in MATLAB. Both C and d are defined as vectors of dimension 1x180. Does anyone have any hint or suggestion on how to solve this problem using lsqnonneg function(or some other technique) in MATLAB? If it was just x instead of exp(2x) it could easily be solved by lsqnonneg! But because of exponential term in the problem I am not able to proceed further. I would appreciate suggestions.
First some math:
Define y = exp(2*x) then the constraint x >=0 is equivalent to y >= 1. An equivalent minimization problem then is:
minimize(over y) norm(c.*y - d)
subject to y >= 1
There are a number of ways to do this in MATLAB. One cool way is to use CVX, if you download the cvx convex optimization package, the code would be:
n = 180;
cvx_begin
variable y(n)
minimize(norm(c .* y - d))
subject to:
1 <= y
cvx_end
Then of course you can do x = log(y) / 2 to get the final value of x