How to get symbolic partial derivative with respect to time [closed] - matlab

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
Let's say I have this function
f(t) = 4*sin(a(t)) + x(t)*y(t) + h + cos(y(t))*sin(x(t))
How would I compute its derivative with respect to time?

You need to declare the variables and the functions inside it as being symbolic and then use diff:
clear
clc
syms a x y t h
a(t) = symfun(sym('a(t)'), t)
x(t) = symfun(sym('x(t)'), t)
y(t) = symfun(sym('y(t)'), t)
F = 4*sin(a(t)) + x(t)*y(t) + h + cos(y(t))*sin(x(t))
DerF_t = diff(F,t)
Giving the following (messy) output:
F = h + 4*sin(a(t)) + cos(y(t))*sin(x(t)) + x(t)*y(t)
DerF_t = x(t)*diff(y(t), t) + y(t)*diff(x(t), t) + 4*cos(a(t))*diff(a(t), t) + cos(x(t))*cos(y(t))*diff(x(t), t) - sin(x(t))*sin(y(t))*diff(y(t), t)
Note that since a(t),x(t) and y(t) are simply defined as functions of 't' we are stuck with their 'symbolic' derivative (I don't know the term for that sorry)...i.e. diff(a(t)) for instance.
Hope it's what you were after!

Related

MATLAB Trigonometry Find Field [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have this trigonometric equation;
cos(2*pi*50*t)+cos(2*pi*100*t)
I want to graphic of equation and I want to find field for a period. How can I do?
Graph:
>> f = #(t) cos(2*pi*50*t) + cos(2*pi*100*t);
>> x = linspace(0, 1/50, 100);
>> y = f(x);
>> plot(x,y)
Area over 1 period:
>> integral(f, 0, 1/50)
or just do it manually:
∫ ( cos(2π·50t) + cos(2π·100t) ) dt =
-1/2π·( 1/50·sin(2π·50t) + 1/100·sin(2π·100t) )
which, evaluated between 0 and 1/50, equals 0.

Plotting a function [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have a function (the hill function) when X and K are the same (x==k) the output should be 0.5, when I test the function it gives a result of 0.5, when I try to plot it, I do not get 0.5 for my Y. Can anyone explain what I am doing wrong?
n = 1;
k = 1;
x = [0:0.01:2].';
y = (x.^n)/((x.^n)+(k.^n));
plot(x,y);
n = 1;
k = 1;
x = [0:0.01:2].';
y = (x.^n)./((x.^n)+(k.^n));
plot(x,y);
You missed a dot before the division.

Unconstrained Optimization [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
function f = objfun(x)
f = exp(x(1)) * (4*x(1)^2 + 2*x(2)^2 + 4*x(1)*x(2) + 2*x(2) + 1);
x0=[-1,1];
options = optimoptions(#fminunc,'Algorithm','quasi-newton');
[x,fval,exitflag,output] = fminunc(#objfun,x0,options);
x,fval,exitflag,output
end
Can you please help me in running the code?
Convert f to a function handle as
fun = #(x) exp(x(1)) * (4*x(1)^2 + 2*x(2)^2 + 4*x(1)*x(2) + 2*x(2) + 1);
then call fminunc with
[x,fval,exitflag,output] = fminunc(fun,x0,options);
As a side note, don't ever call fminunc from within the objective function.

How to solve non-linear mathematical equation in matlab? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I've two equations as:
x = c1 - y;
y = c2*c3*x / (1+c3*x);
where c1, c2 and c3 are constants. How to solve these equations in MATLAB? Please help.
Since I'm in a good mood this morning:
x = c1 - y;
y = c2*c3*x / (1+c3*x);
Now, pen and paper:
y = c1 - x
c1 - x = c2*c3*x / (1 + c3*x)
(c1 - x) * (1 + c3*x) = (c2 * c3 * x)
(c1 - x) * (1 + c3*x) - c2*c3*x = 0
You should be able to use fzero or roots to solve this by yourself.

Solve two equations with two unknowns parameters [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have these two equations and I want to find the values of these two parameters:
9.393e(16) = ((N*K)/(K + 0.0045))*(1 - exp (-(K + 0.0045)*120))
1.376e (17) = ((N*K)/(K + 0.0045))*(1 - exp (-(K + 0.0045)*240))
How can I solve it in matlab or wolfram please
I guess a hand calculator is sufficient for that.
Call:
a = 9.393e(16)
b = 1.376e (17)
Q = (N*K)/(K + 0.0045)
f = exp (-(K + 0.0045)*120) => exp (-(K + 0.0045)*240) = f^2
You have:
a = Q (1 - f)
b = Q (1 - f^2)
so
a/b = (1 - f) / (1 - f^2) = 1 / (1 + f)
thus
f = b/a - 1
You can take the log at both sides and solve for K.
-(K + 0.0045)*120 = log(b/a - 1)
To find N the equation is again just linear.
You can solve simultaneous non-linear equations in MATLAB via FSOLVE or LSQNONLIN. However, this requires the Optimization Toolbox.
See this MathWorks knowledgebase article.
Given the magnitude of the LHS of your equations, I would not be surprised if you see some numerical instability. You might want to do this problem by hand as suggested by Acorbe.