MATLAB Answers

Convert to MATLAB Code

1 view (last 30 days)

  2 Comments

Mushahid Rasul
Mushahid Rasul on 20 Mar 2020
function f = function_5(x)
a = 1;
sum1 = 0;
for i =1: size(x,1)
for j=1:25
sum1 = (1/(j + (x(i,1) - a)^6+(x(i,2) - a)^6));
end
f(i) = 0.002 + sum1;
end
end
My attempt. Would this be correct?
Walter Roberson
Walter Roberson on 20 Mar 2020
No, the equation involves which in MATLAB would be a(i,j)

Sign in to comment.

Accepted Answer

Prabhan Purwar
Prabhan Purwar on 26 Mar 2020
Hi,
Following code illustrates the implementation of the above equation:
x=[2 3]; %x vector
f=function_5(x);
function f= function_5(x)
a=ones(2,25); % a(i,j)
sum1=0;
sum=0;
for j=1:25
for i=1:2
sum1= sum1 + (x(i) - a(i,j))^6;
end
sum = sum + 1/(j+sum1);
suom1=0;
end
f=0.002+sum;
end
Hope it helps!!

  4 Comments

Show 1 older comment
Prabhan Purwar
Prabhan Purwar on 26 Mar 2020
This was his very first question, I didn't felt it's a bad idea to help someone.
Walter Roberson
Walter Roberson on 26 Mar 2020
We try to act more like tutors, ideally talking about what the challenges are with the approach a poster has taken, to guide them towards being able to find a solution themselves. This leads them to a greater understanding of programming and of MATLAB and of the topic they are working on -- which is the goal of taking courses. When we give guideance instead of finished solutions, the person can correct the work they themselves have done, and submit the result in good conscience that they did the work and understand the solution.
Mushahid Rasul
Mushahid Rasul on 26 Mar 2020
I’m sorry if I have caused any problems, I had done it on my own but was a little unsure about the equation conversion into Matlab. Thank you for your help. Also I’ll make sure not to ask for complete solutions in the future.

Sign in to comment.

More Answers (0)


Translated by