In an assignment A(I) = B, the number of elements in B ....? [closed] - matlab

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 9 years ago.
Improve this question
When i run my program for 4 iterations there is no problem but if i run it for more than 4 i get the following error
In an assignment A(I) = B, the number of elements in B
and
I must be the same.
for the following line
Corresponding_value_of_x1(i)=x1(f==Lowest_value_of_the_objective_function(i));
Please help.
maxit=5
iga=1
x1=(6.*bin2dec(String_1))./1023
x2=(6.*bin2dec(String_2))./1023
for i=1:1:maxit
f=(x1.^2+x2-11).^2+(x1+x2.^2-7).^2;
%Displaying results from the iteration
i;
Lowest_value_of_the_objective_function(i)= min(f);
Corresponding_value_of_x1(i)=x1(f==Lowest_value_of_the_objective_function(i));
nx1=(6.*bin2dec(New_string(1)))./1023;
nx2=(6.*bin2dec(New_string(2)))./1023;
x1=nx1;
x2=nx2;
end
Corresponding_value_of_x1

It looks like you're trying to find the minimum of a vector, then the corresponding location of that value. min will do all that at once, avoiding the problem you're running into:
[Lowest_value_of_the_objective_function(i) Corresponding_value_of_x1(i)] = min(f);
Note that your error is occurring because the same minimum value is appearing more than once. This code will return the first of those minimum values. If you want different behavior, you'll have to code it.

Related

how to substitute one funtion into integration with infinity as upper limit in maple? [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 3 days ago.
This post was edited and submitted for review 3 days ago.
Improve this question
When I substitue the function in to the integration with infinity as upper limit, maple fails.
https://i.stack.imgur.com/VAkeO.jpg
https://i.stack.imgur.com/ujfGS.jpg
I can substitue successfully the function in to the integration with another variable as upper limit as shown in the figure. I hope to keep the infinity symbol in the substituted result.
The following is the plain text code:
f := u -> theta*exp(-theta*u);
subs(f(u__b) = f(u), int(h(Q, u__b)*f(u__b), u__b = q__a .. infinity));
subs(f(u__b) = f(u), int(h(Q, u__b)*f(u__b), u__b = q__a .. IN));

How to create a a:d:b vector to create and display "sin(0), sin(pi/n), sin((2*pi)/n), . . . , sin(2*pi)]" [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have been trying for a while to get this to work but I don't seem to be getting any closer to a solution.
I'm not sure of what the pattern is and what to write for the "d" value in a:d:b
Clearly you want to start from 0 (a) and go to 2*pi (b).
Now the question comes what is your step size (d)?
From your example you can see that you are changing from 0 to pi/n.
And from pi/n to 2*pi/n.
This means your step size is d=pi/n
Once you defined your n, e.g:
n=10;
you can do the rest like this:
x=0:(pi/n):(2*pi)
y=sin(x);

Why I get this Error? (State Space) [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 6 years ago.
Improve this question
Could someone explain me what I must change in my model?
Model
The error messages are pretty clear and self-explanatory. The reason you get the error is because B is of dimension 4x2 and you are trying to do B * Xr where Xr is of dimension 1. According to your equation, you need to do B*U where U = [dXr/dt; Xr];. However, using the derivative block is never a good idea in Simulink if you can avoid it, especially with a step input. Think about how you want to formulate the inputs to your state-space.

How can I write this using Matlab with for loop, ones, and zeros? [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 7 years ago.
Improve this question
Please help me out with this code:
for i = 1:n
u(t - a_i - td_i);
end
where:
u: step function
t: time vector with n elements
a_i, tau_i, and td_i: variables that change inside for loop
I guess I need to use zeros and ones, but how can I do this correctly?
Simple function to sum the value inside the loop:
func = #(t) sum(t > a + td)
func(t) will be the sum of the foor loop

need help for matlab [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 9 years ago.
Improve this question
This figure illustrates my problem:
t (in the X1 calculation) value changes from 0 to etz. If its value reaches etz it has to start from 0 again and again.
This situation has to continue during simulation (I need a loop!). However, t is simulation time and I cannot force it to be zero. So maybe I need a parallel time to the simulation time but I don't how to create it.
Use modulo operator.
http://www.mathworks.com/help/matlab/ref/mod.html
For example:
X1 = abs((mod(t,e*tz)-e*tz/2)/(1.125*c*tz))
This part:
mod(t,e*tz)
Will be >= 0 and < e*tz and will repeat the way you want.
In the future, please provide a better title for your question. Also, providing a screen shot of your code is not the preferred way to include code.