I tried this
MIN 0.2 [ 2 + #ABS( 2x^2+2x-3) + #ABS( 2x^3+5x-2) + #ABS( 2x^4+2x^3+5x^2+7x-2.5) ]
For the equation
min 0.2[2+|2x^2+2x-3| + |2x^3+5x-2| + |2x^4+2x^3+5x^2+7x-2.5|]
But getting error
I think your problem in the way of writing the script of the equation.
so, I tried this and I got the solution.
MIN = 0.2*( 2 + #ABS( 2*x^2+2*x-3) + #ABS( 2*x^3+5*(x-2)) + #ABS( 2*x^4+2*x^3+5*x^2+7*(x-2.5)));
Related
how can I pretty print a transfer function in matlab?
H(s)=4.25/((0.3s+1)(22.5+1)(40s+1))
And this is how I've implemented it in matlab:
Hf=tf(K,conv(conv([T1 1],[T2 1]),[T3 1]));
But the result is :
Hf = 4.25/(270 s^3 + 918.8 s^2 + 62.8 s + 1)
1) How can I display it in the same format as in the first equation?
2) How can I display a controller in a PID format ?
Kp(1 + Ti/s + Td*s)
I am trying to find the denominator of a given fraction G, but I cannot find a way to use MATLAB's built-in functions without oversimplifying the fraction, and losing important information.
I've tried using MATLAB's built-in commands "numden", "simplify", and "simplifyFraction" but they keep cancelling equal terms from the numerator and denominator. This is normally okay, but for my application, I need to know all values in the denominator which might cause a hole/instability in the function, G.
I've tried looking into the additional constraints within those functions like "IgnoreAnalyticConstraints", but they don't seem to fix the issue. I've simplified my code to isolate my problem below with my current attempts:
syms 's'
G = 2/(s - 1) + 1/(s + 1) - 4/((s - 1)*(s + 1));
[n,d]=numden(G)
G_simp=simplify(G)
G_simpC=simplify(G,'IgnoreAnalyticConstraints',false)
G_simpF=simplifyFraction(G)
Output:
n = 3
d = s + 1
G_simp = 3/(s + 1)
G_simpC = 3/(s + 1)
G_simpF = 3/(s + 1)
Here is an example fraction input:
G = 2/(s - 1) + 1/(s + 1) - 4/((s - 1)*(s + 1))
which simplifies to:
G = 3*(s - 1)/((s - 1)*(s + 1)). <-desired result
I am trying to keep the fraction in this simplified form, but the built-in commands will cancel the (s-1) terms resulting in:
G = 3/(s + 1). <-actual result
You can use the Control System Toolbox:
s= tf([1 0],1);
G = 2/(s - 1) + 1/(s + 1) - 4/((s - 1)*(s + 1))
zpk(G)
The code s= tf([1 0],1); creates a variable s. It contains a Transfer Function object that represents the transfer function f(s)=s. The line
G = 2/(s - 1) + 1/(s + 1) - 4/((s - 1)*(s + 1))
creates a Transfer Function object that contains the corresponding transfer function. And zpk(G) converts this function to the zero/pole/gain form.
The result of the code above is
G =
3 s^3 - 3 s^2 - 3 s + 3
-----------------------
s^4 - 2 s^2 + 1
Continuous-time transfer function.
ans =
3 (s+1) (s-1)^2
---------------
(s+1)^2 (s-1)^2
Continuous-time zero/pole/gain model.
I am developing an equilibrium model where producers weight benefits and costs to choose the optimal time they work. However, the relevant benefit and cost functions are both rational, which results in a complex first-order derivative of the problem. When parameter values are introduced, I get systems of 3 equations in 3 variables just like the following:
eq1 = (10940*((12034*x)/35 + (1094*y)/5 + (2734*z)/25))/(7*(((12034*x)/35 + (1094*y)/5 + (2734*z)/25)^2 + 640000)) - (10940*((12034*x)/35 + (1094*y)/5 + (2734*z)/25)^3)/(7*(((12034*x)/35 + (1094*y)/5 + (2734*z)/25)^2 + 640000)^2) == x^3/5184
eq2 = (10940*((1094*x)/15 + (51418*y)/105 + (2734*z)/25))/(7*(((1094*x)/15 + (51418*y)/105 + (2734*z)/25)^2 + 640000)) - (10940*((1094*x)/15 + (51418*y)/105 + (2734*z)/25)^3)/(7*(((1094*x)/15 + (51418*y)/105 + (2734*z)/25)^2 + 640000)^2) == y^2/576
eq3 = (5468*((1094*x)/15 + (1094*y)/5 + (30074*z)/75))/(5*(((1094*x)/15 + (1094*y)/5 + (30074*z)/75)^2 + 490000)) - (5468*((1094*x)/15 + (1094*y)/5 + (30074*z)/75)^3)/(5*(((1094*x)/15 + (1094*y)/5 + (30074*z)/75)^2 + 490000)^2) == z^2/576
It has usually taken around 48 hs for MATLAB to find solutions for such systems of equations - when it does find them - using the solve command. Is there a more efficient way to complete this task? (I do have a pretty clear guess at what solutions should look like: all three outcome variables are expected to be within the [0,12] interval.)
I have an equation denoted as 'a' in the code. I am trying to solve this equation for different values. When I use solve(eq), it does not solve the problem and gives an error. The solution must be in the form 4 by 1, I guess.
syms x y t
a = 3*x^2 + 2*y +7;
b = rand(4,2);
eq = subs(a,{x,y},{b(:,1)*t,b(:,2)*t,})
eq = (114796936454163404704655535315507*t^2)/81129638414606681695789005144064 + (7027663972423957*t)/4503599627370496 + 7
(2049112225923387932688645929427*t^2)/20282409603651670423947251286016 + (730715964868191*t)/4503599627370496 + 7
(8261891359675172983093065745827*t^2)/20282409603651670423947251286016 + (4185582312538139*t)/2251799813685248 + 7
(95262076673210081160325846940403*t^2)/81129638414606681695789005144064 + (1746749665163685*t)/1125899906842624 + 7
solve(eq)
PS: Since I run this code inside a different function, I am trying to save time here by not using loops.
First, I need to state that I'm not exactly a math lover or an avid Matlab user. This is college homework that I have been trying to solve for the last 3 hours with no luck. I have googled like crazy, even asked for help via Facebook (where I got replies, but nothing that solved my questions).
This is my first time using this software and I need to graph some things really quick. But no matter how much I read I keep getting syntax errors and the like.
Basically, I have this equation:
4*x^2 + y^2 + z^2 - 8*x + 2*y + 3 = 0
And I'm trying to plot it/graph it. I thought it would be very straightforward but I'm having problems doing it.
Google searches have shown me the functions ezplot() and ezsurf(), but:
When I do ezplot('4*x^2 + y^2 + z^2 - 8*x + 2*y + 3'), I get the following error:
??? Error using ==> char
Cell elements must be character arrays.
Error in ==> ezplot at 158
fmsg = char(f);
And when I do ezsurf('4*x^2 + y^2 + z^2 - 8*x + 2*y + 3')
The expression 4*x^2 + y^2 + z^2 - 8*x + 2*y + 3 must only have 2 symbolic variables
Error in ==> ezgraph3>surfplot at 526
[F,var] = ezfixfun(F,fargs,flabel);
Error in ==> ezgraph3 at 49
[dummy,h] = surfplot(f,domain,surfstyle,cax,Npts,fixdomain,flabel,fargs);
Error in ==> ezsurf at 65
h = ezgraph3('surf',args{:});
Again, this is really my first time using this software. The teacher didn't give us any explanation so I have no idea of what these errors are supposed to mean, let alone solving them. I have no idea of what I'm doing or what I am supposed to do.
I have tried using solve() to solve for 'z' first and then plot the two results I get.
s = solve('4*x^2 + y^2 + z^2 - 8*x + 2*y + 3', 'z')
s =
-(- 4*x^2 + 8*x - y^2 - 2*y - 3)^(1/2)
(- 4*x^2 + 8*x - y^2 - 2*y - 3)^(1/2)
But that's not working either. When I use ezplot() it tells me to use ezsurf, and when I use ezsurf() it tells me about a variable "h" that I have never even declared:
>> ezsurf('-(- 4*x^2 + 8*x - y^2 - 2*y - 3)^(1/2)', '(- 4*x^2 + 8*x - y^2 - 2*y - 3)^(1/2)')
??? Undefined function or variable "h".
Error in ==> ezgraph3 at 66
hh = h;
Error in ==> ezsurf at 65
h = ezgraph3('surf',args{:});
Any help plotting that will be really appreciated. My head is going to explode because people have been telling me this is supposed to be really straightforward.
Thank you!
The following works for me:
ezsurf('(8*x - 4*x^2 - y^2 - 2*y -3)^(1/2)');
Note that ezsurf accepts a function of 2 dimensions (that maps into a 3rd dimension). So you must express the function in the form f(x, y) = blah, where blah is what you want as your input to ezsurf. All I did was re-arrange your function into the form z = blah, and then input blah to ezsurf.
Oh, and two other things, 1) The resulting graph only tells half the story, since the square root of z^2 can be z or minus z (by default, matlab takes the positive square root). 2) The function as above can only be analyzed without complex numbers (such as I've done here) for a very restricted domain of x and y.